Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m in java one and need help with this code. please follow the givne direction

ID: 3691429 • Letter: I

Question

I'm in java one and need help with this code. please follow the givne directions and test your program to make sure it works as it is required. I will apreciate your help. please follow stept by step the given directions. thank you.

Programming Concepts

Classes

Objects

Assignment Description

Write a program that will simulate a combat game between a user and the computer

You will have two files:

1 -- Player.java
  § This file contains the template for a game playe

§ Here is its UML diagram:

- health : Integer

- name : String

+ << Constructor >> Player ( n : String )

+ attack ( ) : Integer
+ takeDamage ( damage : Integer )
+ getHealth ( ) : Integer

+ getName ( ) : String

§ Variable descriptions

- health : Holds the total health points for the player

- name : Holds the player's name

- Constructor

o Initializes the name for the player

o Initializes health to 20

§ Method descriptions

- Constructor

o Initializes the name for the player

o Initializes health to 20

attack ( )

o Randomly chooses an attack between "Kick", "Punch", and "Yell"

o Also randomly calculates the amount of damage dealt (between 0 and 7)

o Prints out the attack and damage dealt

o Returns the damage dealt

takeDamage ( int damage )

o Reduce the player's health by the amount of damage that the player took

getHealth ( )
o Returns the player's health

getName ( )
o Returns the player's name

2-- JavaCombat.java

§ This file contains the main method, which contains the game logic

- See Assignment Suggestions on how to implement the main method

Assignment Suggestions

1) The main method in JavaCombat.java

> Create the Player object for the computer

> Ask the user for the player's name

> Create the Player object for the user with the given name

> Loop while the user wants to continue or until someone dies

> Refresh the screen and display the divider bar

> Have the user's player attack, and store the damage dealt

> Have the computer take the dealt damage

> If the computer dies

--Display a win message for the user

--End the game

> Have the computer attack, and store the damage dealt

> Have the user take the dealt damage

> If the user dies

--Display a win message for the computer

-- End the game

> Display the health status for both players

> Ask if the user wants to continue or quit

--Display the final health status for both players before the game ends

2 ) To refresh the screen, use the following print statement:

System.out.print(" ");

The " " escape character is a "form feed". It will appear to "refresh" the screen every time, but what it actually does is advance the screen by one screen length, so you can still see the history of what your program printed out to the screen.

example output

Enter name: Sean

================================================

Sean's turn!
Sean used "Punch" and dealt 1 damage!

Computer's turn!
Computer used "Punch" and dealt 6 damage!

==============================

Sean's Health: 14

Computer's Health: 19

==============================

Enter 'c' to continue, or 'q' to quit: c

================================================

Sean's turn!
Sean used "Yell" and dealt 0 damage!

Computer's turn!
Computer used "Punch" and dealt 1 damage!

==============================

Sean's Health: 13

Computer's Health: 19

==============================

Enter 'c' to continue, or 'q' to quit: c

================================================

Sean's turn!
Sean used "Punch" and dealt 4 damage!

Computer's turn!
Computer used "Punch" and dealt 6 damage!

==============================

Sean's Health: 7

Computer's Health: 15

==============================

Enter 'c' to continue, or 'q' to quit: c

================================================

Sean's turn!
Sean used "Yell" and dealt 4 damage!

Computer's turn!
Computer used "Kick" and dealt 5 damage!

==============================

Sean's Health: 2

Computer's Health: 11

==============================
Enter 'c' to continue, or 'q' to quit: c

================================================

Sean's turn!
Sean used "Yell" and dealt 2 damage!

Computer's turn!
Computer used "Kick" and dealt 2 damage!

Sean had died. Computer has won!

==============================

Sean's Health: 0

Computer's Health: 9

==============================

player

- health : Integer

- name : String

+ << Constructor >> Player ( n : String )

+ attack ( ) : Integer
+ takeDamage ( damage : Integer )
+ getHealth ( ) : Integer

+ getName ( ) : String

Explanation / Answer

Player.java:

import java.util.*;
public class Player {
       private int health;
       private String name="Temp name";
       Player(String n)
       {
           health = 20;
           name = n;
       }
       int attack()
       {
           String att="temp";
           Random rand = new Random();
           int attype = rand.nextInt(3); // 0-9.
           if(attype==0)att = "Kick";
           if(attype==1)att = "Punch";
           if(attype==2)att = "Yell";
           int damage = rand.nextInt(7);
           System.out.println(name+ " used "+ att+ " and dealt "+ damage +" damage!");
           return damage;
       }
       void takedamage(int damage){
           health -= damage;
           if(health<0)health=0;
       }
       int getHealth()
       {
           return health;
       }
       String getName()
       {
           return name;
       }
}

JavaCombat.java:

import java.util.*;
public class JavaCombat {

   public static void main(String args[])
   {
       Scanner s = new Scanner(System.in);
       Player comp = new Player("Computer");
       System.out.print("Please enter the player name:");
       String pname = s.next();
       Player pp = new Player(pname);
       int dam;
       while(true)
       {
           System.out.println("================================================");
           System.out.println(pname+"'s turn!");
           dam = pp.attack();
           comp.takedamage(dam);
           if(comp.getHealth()==0)
           {
               System.out.println("Computer has died."+pname+" has won!");
               break;
           }
           System.out.println("Computer's turn!");
           dam = comp.attack();
           pp.takedamage(dam);
           if(comp.getHealth()==0)
           {
               System.out.println(pname+" has died.Computer has won!");
               break;
           }
           System.out.println("==============================");
           System.out.println(pname+"'s health: "+pp.getHealth());
           System.out.println("Computer's health: "+comp.getHealth());
           System.out.println("==============================");
           System.out.println("Enter 'c' to continue, or 'q' to quit:");
           String ch = s.next();
           if(ch.equals("q"))
           {
               break;
           }
           else if(ch.equals("c"))
           {
               continue;
           }
       }
       System.out.println("==============================");
       System.out.println(pname+"'s health: "+pp.getHealth());
       System.out.println("Computer's health: "+comp.getHealth());
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote