Question: I need help with this using Java please. Define an abstract class called BattleEvent which represents an action being taken by an Actor a. It

I need help with this using Java please.

Define an abstract class called BattleEvent which represents an action being taken by an

Actor

a. It will need an owner and a target

i. These are both Actors

b. It will also need an amount of damage it does and a priority

i. Both of these should be an int. More on priority later.

c. Provide the signature for an abstract void method called doEvent which takes no

parameters.

This is the Actor Class (if needed):

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; //currentHealth 0 means actor is dead, return true, otherwise false.

return true;

}

else{

//return true;

return false;

}

}

//function called damage which decrease or increase actor's health by the parameter passed.

public void damage(int reduceHeealthBy)

{

if((this.currentHealth - reduceHeealthBy) < 0)

{

this.currentHealth =0; //you cannot decrease health of a dead person as 0 means actor is dead.

}

else if((this.currentHealth - reduceHeealthBy) < STARTING_HEALTH)

{

this.currentHealth-=reduceHeealthBy;

}

else

{

System.out.println("You cannot increase the health more than "+STARTING_HEALTH);

}

}

//function called print which prints actors name and present health

public void print()

{

System.out.println("Name: "+name);

if(isActorDead() == true)

{

System.out.println("Actor is dead");

}

else

System.out.println("Current health: "+currentHealth);

}

}

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!