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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started