Question: I need help with number 2 using Java, thank you! 1. Write a new class called Actor which represents a single fighter in combat. a.

I need help with number 2 using Java, thank you!

1. Write a new class called Actor which represents a single fighter in combat.

a. All Actors have a name, and a current amount of health.

b. Define a constant STARTINGHEALTH which is equal to 100.

c. The Actor constructor should take a name and set the current health to the constant.

d. Other classes will need to know this Actors name and if they are dead.

i. At what point would someone die in combat?

2. Provide a method that allows this Actor to take damage.

a. This should take an int parameter and reduce their health by that much.

b. In order to save space, this will also function as your healing method

i. If the parameter is negative, subtracting it from your health would increase it

ii. An Actor cannot have more health than STARTINGHEALTH

here is the actor class:

public class Actor{

String name; int currentHealth; static final int STARTING_HEALTH = 100; public Actor(final String name,final int currentHealth){ //Constructor to set the name and current health this.name=name; this.currentHealth=currentHealth; } public String getActorName(){ //method to get the actor name.can be invoked from other classes return this.name; } public boolean isActorDead(){ //Method to check if the actor is alive if(this.currentHealth==0){ return false; } else{ return true; } } }

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!