Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

Who should apply a scorecard approach?

Answered: 1 week ago