Create a new project named coliseum create a private


Application Assignment

1. Create a new project named Coliseum.

2. The idea of this project is to simulate a fight per turns between two warriors.

3. Create a new abstract class named Warrior, in a package named coliseum.

4. In the abstract class Warrior

a. Create a private integer variable named health, with a hard-coded value of 30. All warriors have 30 health points.

b. Create a private integer variable named attack. The attack points of each type of warrior are different.

c. Create a private integer variable named defense. The defense points of each type of warrior are different.

d. Create a setter and a getter for each variable. In eclipse, a symbol appears at the beginning of the line, where a variable was created. If you click on it, it will show more options such as automatically create a setter and a getter for that variable.

e. Create another public method named attack. This method returns the value of the damage that the opponent will receive. This method receives the opponent (Warrior) as parameter. The damage is equal to "the attack points of the current warrior' minus "the defense points of the opponent". If the damage is a negative value, then set damage to 0. Finally, return the damage value.

f. Create another public method named receivesDamage. This method does not return anything. This method receives the damage (integer value) as parameter. The health points of the current warrior is updated to "the health points of the current warrior" minus "the damage". If the resulting health points is a negative value, then set health points to 0.

g. Create a public abstract no-argument method named getReady. This method sets the attack points and defense points of a warrior.

5. Create a subclass of Warrior named Spartan

a. Override the method getReady

i. Call the method setAttack with a value of 6. This will set the attack points of all Spartans to 6.
ii. Call the method setDefense with a value of 5. This will set the defense points of all Spartans to 5.

6. Create a class with a main method named Arena

a. Copy the following code to the main method

Warrior defender = new Spartan();
Warrior attacker = new Spartan();
do {
// Switch warriors' roles
Warrior temporal = attacker;
attacker = defender;
defender = temporal;
// Get ready
defender.getReady();
attacker.getReady();
// Attack
defender.receivesDamage(attacker.attack (defender));
} while (defender.getHealth()>0);

7. Run your code.

8. It should compile and run. However, nothing is displayed.

9. Let's display some information about the fight.

a. In the method attack (no overriding), before returning the damage, display the attack points of the current warrior, and display the defense points of the other warrior.

i. System.out.println("Attack level: " +this.getAttack());
ii. System.out.println("Defense level: "+ otherWarrior.getDefense());

b. In the method receivesDamage (no overriding), display health points of the warrior after receiving damage.

i. System.out.println("Current health: " + this.getHealth());

10. Run your code.

11. It should compile and run. Information of the fight is displayed. However, it is not clear who is attacking and defending.

12. Let's add more information.

13. In class Warrior, add a new instance variable named name. Add the corresponding getter and setter.

14. Create a constructor in class Spartan which receives as an argument the name of the Spartan warrior and store it in the variable name.

15. Create a new interface named identifiable. A class which implements this interface must have a method to return a String value which represents the object.

a. Define a method named getldentifier. This method must return a String value.

16. Make the class Warrior implement the interface identifiable.

17. Add the public method getldentifier. This method will return the value of the variable name.

18. Call the method getldentifier in methods attack and receivesDamage, so they can display the identifiers of the warriors, for instance

Leonidas' Current Health: 1
Leonidas' Attack Level: 6
Stelios' Defense Level: 5
Stelios' Current Health: 0

19. Call the Spartan constructors with names for the warriors.

20. Run the program.

21. Create another type of warrior (subclass of warrior) named Gladiator. The defense points of a Gladiator are always 4. The attack points of a Gladiator are a random number between 1 and 10.

22. Spartan vs Gladiator. Who wins?

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a new project named coliseum create a private
Reference No:- TGS02672593

Now Priced at $30 (50% Discount)

Recommended (91%)

Rated (4.3/5)