Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please do this assignment in Java: Copy your character classes from called project3.characters. Create an array of several (at least 4) game characters of different
Please do this assignment in Java:
- Copy your character classes from called project3.characters.
- Create an array of several (at least 4) game characters of different types.
- 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
This is previous assignment that had project3.characters:
- Create two packages in eclipse: project3 and project3.characters. (Yes, that says project3. We will be using these classes in Project 3).
- 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.
- Write a toString() method for your character classes that displays the name, class, strength, & health of the character
- Create a driver class that simulates a battle between two characters. Your logic for battle does not need to be complex.
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
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