Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

1. What is your religious upbringing?

Answered: 1 week ago