Question: Create a class for a Fighter in a combat game. The Fighter class has the following instance variables: - name - health points -- a

Create a class for a Fighter in a combat game. The Fighter class has the following instance variables:

-name

-health points -- a double representing health. 0 or below is dead.

-strength points -- a double representing the strength of the Fighter

The Fighter class also has the following methods

-public void setName(String n) A mutator method for the name. Note: Do not input the name in this method. That belongs in the main method.

-public void setHealth(double h) A mutator method for the health (Do not input the health here.)

-public void setStrength(double s) A mutator method for the strength (Do not input the strength here.)

-public String getName() An accessor method for the name

-public double getHealth() An accessor method for the health

-public double getStrength() An accessor method for the strength

-public void attack(Fighter foe) Calculates a change in the health of the foe parameter by multiplying the strength of this Fighter by Math.random(), then changing the health of the foe ;by the change.

-public boolean isDead() Returns true if the Fighter's health is less than or equal to 0, else false

-public void printChange(double c,Fighter nme) Prints a message displaying the name of the nme Fighter, the amount of change in health c, and the resulting level of health for nme. Called from attack.

Also write a driver program, instantiating two Fighters, assigning them names, strengths and health values, for example, 10 for health and 5 for strength for both, then loop until one of them is dead, taking it in turns for one to attack the other. Do not allow a dead Fighter to attack a living one, or vice versa. This main method can be in the same file or in a different file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!