Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming question Create four classes to simulate dungeon adventurers. One class representing the adventurer (Adventurer.java), one class representing the knight (Knight.java), one class representing

Java Programming questionimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Create four classes to simulate dungeon adventurers. One class representing the adventurer (Adventurer.java), one class representing the knight (Knight.java), one class representing the archer (Archer.java), and one class to test your code (Dungeon Driver.java). Some restrictions No imports are allowed. Adventurer.java This Java file represents an adventurer. Instance Variables: - Adventurers have a name attribute. The variable should be private with no getters or setters. - Include an attack attribute. Once assigned, the attack value should never change. - Include a health attribute. Constructors: - Include a constructor that takes in name, health, and attack values. - You should not have any other constiuctors Methods: 1. Adventurers can attack each other. * Every adventurer has their own unique attack, so this method should be abstract. * This method should take in another Adventurer as its only parameter 2. An adventurer should also be able to drink a magical health potion. * This should increase their health by a value of 15 * An adventurer can have a health value that is higher than their original health value * Even if an adventurer has no health remaining, they can still drink a potion. O health does not mean they're dead, they're just too exhausted to keep fighting. 3. equals method * Override from Object * Two adventurers are equal if they have the same health, attack and name values Knight.java This Java file represents a knight. A knight is a type of Adventurer and should have all the behaviors of the adventurer. Instance Variables: - A squire is a knight's helper. Knights should have an attribute for the presence of squire. - No other instance variables should be created in Knight Constructors: - A constiuctor that sets a knight's name, health, attack, and squire existence. - A constructor that takes in a name and assigns the following default values: * Health: 100 * Attack: 15 * hasSquire: true - No other constructors should be created Methods: 1. A knight can attack. * Attack must override the method from Adventurer * If any null parameters are passed in, this method should not do anything * A knight may only attack if they have more than 0 remaining health * If the knight does not have a squire, damage dealt should be equal to the knight's attack value. If the knight has a squire, damage dealt should be twice the knight's attack value. * The damage should be inflicted on the defending adventurer's health. If the attack brings the defending adventurer's health below 0, set it to 0 instead 2. A knight should be able to challenge another knight for their squire * This method should take in another knight as its only parameter * If any null parameters are passed in, this method should not do anything * A knight can only attempt to steal a squire if the following are true: the knight has more than 0 health, the knight doesn't have a squire, and the other knight (who's being stolen from does have a squire. * The challenge can still occur if the defending knight has 0 health * When the conditions above are met, the squire-stealing knight makes one attack on the other. If the attacked knight's health hits 0, it loses its squire. The squire-stealing knight gets the squire. If the attacked knight's health doesn't hit zero, it should attack the squire stealing knight in revenge. Don't change any squire attributes in the revenge attack. Only make one revenge attack. 3. equals method * Must override * Two knights are equal if they have the same health, attack, name and squire values. 4. toString method * Must override * Returns "Name: {name}, Health: {health), Attack: {attack), Squire: true/false" 5. Getters and Setters as appropriate Note: Class must follow the rules of encapsulation and abstraction. Archer.java This Java file represents an archer. An archer is a type of adventurer and should have all the behaviors of the adventurer. Instance Variables: Archers always carry arrows, and they should have an attribute for how many they currently have. By default, archers carry 10 arrows. - No other instance variables should be created in Archer Constructors: - A constructor that takes in name, health, and attack values - A constructor that takes in a name and assigns the following default values: * Health: 75 * Attack: 40 - No other constructors should be created Methods: 1. An archer can attack * Attack must override from Adventurer * If any null parameters are passed in, this method should not do anything * An archer is only able to attack if they have at least 1 airow left and more than 0 health * Damage dealt should be equal to the archer's attack value * The damage should be inflicted on the defending adventurer's health. If the attack brings the defending adventurer's health below 0, set it to 0 instead * After the attack, reduce the number of arrows the archer has by 1 2. equals method * Must override * Two archers are equal if they have the same health, attack and name values. 3. toString method * Must override * Returns "Name: {name}, Health: {health), Attack: {attack), Arrows: {# arrows}" 4. Getters and Setter's as appropriate Note: Class must follow the rules of encapsulation and abstraction DungeonDriver.java This Java file is a driver that runs the simulation. Create a Knight with the following fields: Name="Galahad, Health=7, Attack=6, Squire=true Create a Knight with the following fields: Name="Lancelot, Health=30, Attack=5, Squire=false Create an Archer with the following fields: Name="Archie", Health=10, Attack=2, Arrows=10 1. Have the Archer Archie attack the Knight Lancelot. After the attack: Archie should have: Name="Archie, Health=10, Attack=2, Arrows=9 Lancelot should have: Name="Lancelot, Health=28, Attack=5, Squire=false 2. Now have the Knight Galahad attack the Archer Archie. After the attack: Galahad should have: Name="Galahad, Health=7, Attack=6, Squire=true Archie should have: Name="Archie", Health=0, Attack=2, Arrows=9 3. Have the Archer Archie attack the Knight Galahad. Nothing happens, because Archie has Health=0, and so is too tired to attack 4. Have the Knight Lancelot attack the Knight Galahad. After the attack... Galahad should have: Name="Galahad, Health=2, Attack=6, Squire=true Lancelot should have: Name="Lancelot, Health=28, Attack=5, Squire=false 5. Have the Knight Lancelot challenge the Knight Galahad to steal his squire. After the challenge, Galahad should have: Name="Galahad, Health=0, Attack=6, Squire=false Lancelot should have: Name="Lancelot, Health=28, Attack=5, Squire=true

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions