Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code in java For those knights that survived the Knight Fight, it's now time for your next adventure. Sir Jav-a-lot must now travel through JavaBean

code in java
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
For those knights that survived the "Knight Fight", it's now time for your next adventure. Sir Jav-a-lot must now travel through JavaBean Forest in order to get to his final destination. Unfortunately for Sir Jav-A-Lot, it's midnight, visibility is zero and JavaBean Forest is full of the most evil characters! Not just other Knights, but also Oracle Ogres, Linux Leprechauns and those midnight Wally Wal-Mart customers! So the idea is that Sir Jav-A-Lot will encounter random threats throughout this journey of which will be generated at run time, hence polymorphism. 1. Create an Enemy abstract superclass that fights with the Knight with the abstract method fight() that must be overridden and returns an int for damage. 2. The enemy superclass should have a takeDamage() method with an 2. The enemy superclass should have a takeDamage() method with an implementation in the superclass and maintain an int that represents the enemy's health. It should also have all of the appropriate accessors and mutators. 3. The superclass must also have a static getRandomEnemy() method that returns a random Enemy object (use the Random generator in the java library) which it instantiates from one of the three implementations below (this is called a static method factory and is used extensively in the java library). 4. You must also create a custom Exception method that is thrown by the superclass when negative damage is passed to the takeDamage() method as this is invalid (for example InvalidDamageException). 5. When you set up the attack, request how many enemies your knight sees. Call the getRandomEnemy() method that number of times and see how your knight does. Since you don't know which Enemy object will be 4. You must also create a custom Exception method that is thrown by the superclass when negative damage is passed to the takeDamage() method as this is invalid (for example InvalidDamageException). 5. When you set up the attack, request how many enemies your knight sees. Call the getRandomEnemy() method that number of times and see how your knight does. Since you don't know which Enemy object will be returned you must build the class around Enemy (also called building to an interface (or abstract class) rather than an implementation). Note that this uses polymorphism as the driver program has no knowledge of the underlying implementation of Enemy. ote: This is a tough concept to grasp, so start arly and post ALL questions to the discussion 1. Feel free to spice up the fight with different types of moves and attacks that make sense with the type of enemy (like a sorcerer is probably resistant to magic attack and probably uses them often). +10 pts 2. Have at least 3 implementations (i.e. ogre, sorcerer, troll, or whatever you can dream up) of the superclass enemy, with the random encounter of at least 2 of them. You must override both the tostring() method inherited from Object defining the enemy and the fight method inherited from the abstract superclass. +10pts

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

Makers And Takers The Rise Of Finance And The Fall Of American Business

Authors: Rana Foroohar

1st Edition

0553447238, 978-0553447231

Students also viewed these Databases questions

Question

What's your favorite fast food chain?

Answered: 1 week ago

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago