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
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