Question: Do this is Java: Copy your character classes from called project3.characters. Create an array of several (at least 4) game characters of different types. Write

Do this is Java:

  1. Copy your character classes from called project3.characters.
  2. Create an array of several (at least 4) game characters of different types.
  3. Write a driver class that simulates a Battle Royale between the characters in the array. In a loop, select an attacker at random from the array and have them attack a random character. Continue until only one character remains. Print out the name of the winner.

Previous Assignment:

  1. Create two packages in eclipse: project3 and project3.characters. (Yes, that says project3. We will be using these classes in Project 3).
  2. Create a character class hierarchy. You should have at least 1 abstract class and at least 3 types of characters (4 classes total). Each character should implement the following:
    • public int attack() returns the strength of an attack
    • public void hit(int points) reduces the characters health based on the strength of an attack
    • public boolean isAlive() returns a Boolean based on whether or not the characters health is greater than 0.
    • The name, strength, and health of each character.
  3. Write a toString() method for your character classes that displays the name, class, strength, & health of the character
  4. Create a driver class that simulates a battle between two characters. Your logic for battle does not need to be complex

project3.character Classes:

//Character.java package project3.characters; public abstract class Character { /** * The Name. */ protected String name; /** * The Strength. */ protected int strength; /** * The Health. */ protected int health; /** * Instantiates a new Character. * * @param name the name */ public Character(String name) { this.name = name; } /** * Gets name. * @return the name */ public String getName() { return name; } /** * Gets strength. * @return the strength */ public int getStrength() { return strength; } /** * Gets health. * @return the health */ public int getHealth() { return health; } /** * Attack int. * @return the int */ public abstract int attack(); /** * Hit. * * @param points the points */ public abstract void hit(int points); /** * Is alive boolean. * @return the boolean */ public abstract boolean isAlive(); @Override public String toString() { return "Name: " + name + ", Strength: " + strength + ", Health: " + health ; } } 

//=>Hulk.java

//Hulk.java package project3.characters; public class Hulk extends Character { public Hulk(String name) { super(name); this.health = 100; this.strength = 10; } @Override public int attack() { return strength; } @Override public void hit(int points) { this.health -= points; } @Override public boolean isAlive() { return health>=0; } @Override public String toString() { return "[ Class: Hulk, "+super.toString()+" ]"; } } 

//=>Monster.java

package project3.characters; public class Monster extends Character { public Monster(String name) { super(name); this.health = 100; this.strength = 5; } @Override public int attack() { return strength; } @Override public void hit(int points) { this.health -= points; } @Override public boolean isAlive() { return health>=0; } @Override public String toString() { return "[ Class: Monster, "+super.toString()+" ]"; } } 

//=>Venom.java

package project3.characters; public class Venom extends Character { public Venom(String name) { super(name); this.health = 100; this.strength = 15; // more powerful to attack } @Override public int attack() { return strength; } @Override public void hit(int points) { this.health -= points; } @Override public boolean isAlive() { return health >= 0; } @Override public String toString() { return "[ Class: Venom, "+super.toString()+" ]"; } }

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!