Ask Java Expert


Home >> Java

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?

Java, Programming

  • Category:- Java
  • Reference No.:- M92705449
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As