Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions

Question

Evaluate the importance of the employee handbook.

Answered: 1 week ago

Question

Discuss the steps in the progressive discipline approach.

Answered: 1 week ago