Question
JAVA 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.
JAVA
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 implementation in the superclass and maintain an int that represents the enemys 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 dont 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. Note: This is a tough concept to grasp, so start early and post ALL questions to the discussion board! Acceptance Criteria: 1. Have at least 3 implementations (i.e. ogre, sorcerer, troll, or whatever you can dream up) of the superclass enemy, but only encounter 1 of those implementations randomly. You must override both the toString method inherited from Object defining the enemy and the fight method inherited from the abstract superclass. 2. Creation of at least one standard exception used in the book. 3. Creation of at least one custom exception of your own creation. Extra Credit: 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). +10pts 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
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