Question: Java Code Consider an inheritance hierarchy: Warrior, Swordsman and Axeman. Warrior is the parent and Swordsman and Axeman are their children. Warrior provides them the

Java Code

Consider an inheritance hierarchy:

Warrior, Swordsman and Axeman. Warrior is the parent and Swordsman and Axeman are their children. Warrior provides them the variables Attack (int), Defense (int) and Health (int). Moreover, it passes two methods: attack() and defend().

Swordsman changes the definition of attack() by printing out "The swordsman tries to slash the enemy!", while the Axeman defines it by printing: "Axeman says: 'Charge!!!'". Swordsman changes the definition of defend() by printing out "The swordsman tries to parry!", while the Axeman defines it by printing: "I will block it with my axe!".

In main, create a swordsman and an axeman. Provide them their variables through user input. Handle exceptions (for input mismatch). Then in your application try to let the swordsman attack and axeman defend. The application output should look like:

Swordsman: Attack Rate: 10, Defense Rate: 5, Health: 100 Axeman: Attack Rate: 15, Defense Rate: 3, Health: 110 The swordsman tries to slash the enemy! I will block it with my axe!

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!