Question
Just need help what to do with Part 2Part 1 - Revision, Inheritance and Abstract Classes (Weeks 1 and 2) 1.1 - Create the Class
Just need help what to do with Part 2Part 1 - Revision, Inheritance and Abstract Classes (Weeks 1 and 2) 1.1 - Create the Class given the below in the UML diagram and method descriptions. Inventory - int small Potions 1.1 Resources int mediumPotions - int largePotions This section + Inventory) requires only + Inventory(int smallPotions, int mediumPotions, int largePotions) knowledge from + int getSmall Potions() OOF + int getMediumPotions() + int getLargePotions() + boolean usePotion(int choice) + String toString Inventoryo - Should set small potions to 2 medium potions to 1 and large potions to Inventory(int smalipotions, int mediumPotions, int largePotions) - no information provided Accessors - no information provided to String - no infomation provided usePotion - The choice parameter indicates the type of potion to be used. 1 for small 2 for medium and 3 for large. If there is of the potion selected or an invalid value is entered the false should be retumed. Else the number of the particular Eg. If there is 4 small potions, and 1 is passed as choice, then small potions should be reduced by 1 (leaving 3) and true should be returned. 1.2 - Create the AbstractClass given the below in the UML diagram and method descriptions. 1.2 Resources Lecture 3 Hero - int health - int level - int experience - int maxHealth - Inventory inventory Hero) Heroint health, int level, int experience, int maxHealth, Inventory inventory + boolean usePotion(int size) + boolean takeDamage(int amount) + boolean gainExperience(int amount) + setHealth int health) + setMaxHealth int maxHealth) + setExperience(int experience) + incrementlevel) + int getHealth) + int getLevel) + int getMaxHealth() + int getExperience) + Inventory getinventory + display + upgrade Stats() Herol) - Set health to 100, level to 1 experience to 0. maxHealth to 100, and instantiate a new Inventory using the default Inventory constructor and set it to inventory Hero(int health, int level, int experience, int maxHealth Inventory inventory) - no information provided usePotion - Call usePotion from Inventory, if potion is available then if size is increase health by 10. If size is 2 increase health by 50, else if size if 3 increase health by 100. Retum it potion was available. Note. Health should never be greater than maxHealth (you need to set health to maxHealth if it goes over) takeDamage - Reduce health by the amount. If health is below 1 return false, else true gainExperience - Increase experience by amount, il experience is greater than 1000 then set experience to 0. call incrementLevel and return true, else return false setHealth, setMax Health, setExperience - no information provided incrementLevel - Increase level by 1 and call upgradeStats getHealth, getLevel, getMaxHealth.getExplerence, getinventory - no information provided display, upgrade Stats - these are both abstract methods 1.3 - Create the subclasses given the below in the UML diagram and method descriptions. 13 Resources All three of these classes are subclasses of Hero Archer -double bonus xp Archerint health, int levelint experience, int maureath, Inventory Inventory, double bonusexp) in .double BonusExpl) upgrade Stats .toString) Lecture 1.2 3 display ANONG ml Archer-Set bonusExp to 0.5. Set attributes in base class using what you have learnt in 100 Archer(int health, int level, int experience, int maxHealth Inventory inventory, double bonusExp) - to information provided gainExperience - Increase the experience by amount (int amountbonusExp)) and then handle the same as you did in the Hero class getBonusExp - no information provided display - Using System.out, display the Archer as shown below values will be different) Type: Archer Health Level: Experience Fax lealth: Potions - Small: - Medium - Large! alonus Exp upgradeStats - bonusExp becomes bonusExp +0.1. Max health becomes maxHealth + level 10 Health is set to max Health toString - no information provided Warrior Warrior Warrioroint health, int level, int experience, int maxHealth, Inventory inventory) upgrade Stats .toString) Warrior - no information provided Warrior(int health, int level , int experience, int maxHealth, Inventory inventory, double bonusExp) - no information provided display - Using System.out, display the Warrior as shown below values will be different) Type Varrier besteht Leve Experience! Potions - Small Medium: - Large: upgrade Stats - Max health becomes maxHealth + level 12. Health is set to maxHealth toString - no information provided Mage int healRate Mage() +Mage (int health, int level, int experience, int maxHealth, Inventory Inventory, int healRate) + void magic Heal() + int getHealRate() display + upgrade Stats toString() Mage - Set healRate to 10. Set attributes in base class using what you have learnt in 100 Mage(int health, int level, int experience, int maxHealth, Inventory Inventory, Int healRate) - no information provided magic Heal - Increase health by level "healRate (remember that health can never be greater than maxHealth) getHealRate - no information provided display - Using System.out, display the Mage as shown below (values will be different) Hage Health: 100 Level: 1 Experiences Tax Health: 100 Potions Small: Medium: Large: Heal Rate: upgradeStats - HealRate is increased by 10. Max health becomes maxHealth + level 9. Health is set to maxHealth. toString - no information provided 18 Part 2 - Type Checking and Exceptions (Weeks 2, 3 and 4) 2.1 - Create the Classes as described below. YNException class This class should be a subclass of Exception, it should have two constructors 2. 1 Resources a default constructor, and one that accepts a string. IntRange Exception class Lecture 6,7,8 This class should be a subclass of Exception, it should have two constructors. a default constructor, and one that accepts a string. ValueChecker class This should have two static methods 1. named checkValue that accepts three ints (value, min and max) and returns nothing It should throw a IntRangeException if the value is not within min and max 2. named checkValue (Overloading) that accepts a single char and returns nothing. It should throw a YNException if the char is not y or N 2.2 - Create the Methods as described below. In the Adventure class (this was provided see page 3), you are to create the readint 21 Resources method. Delete the placeholder text "To be implemented in this method and the return. Lecture 8 readint method: Appendix 3 The user will have five attempts to enter a correct value. The user must be prompted eg "Enter choice >> The value must be entered, and then checked using the ValueChecker class and appropriate method IntRange Exception and InputmismatchException should be caught and a message should be displayed If a valid value is read it should be returned else after 5 attempts, throw an Exception from the method. readyNChar method: The user will have five attempts to enter a correct value. The user must be prompted eg "Enter choice >> The value must be entered, and then checked using the ValueChecker class and appropriate method 100 Assignment 1-due: Tuesday 27th of April 2021 at 10.00 am p. 6 of 10 YNException and Input MismatchException should be caught and a message should be displayed to the user each time an invalid entry is entered If a valid value is read it should be returned else after 5 attempts, throw an Exception from the method. 2.3 - Create the Methods as described below. in the Adventure dass (this was provided see page 3), you are to create the createHero. 22 Resource method. Delete the placeholder text "To be implemented in these methods as you go Lecture 4,6 createHero method: If a hero already exists (not null) you must check if the user wants to overwrite the hero Prompt the user appropriately and use the readyNChar method to validate the input if an exception is throw then it must be caught (This will be after 5 attempts). If t is caught, inform the user that no valid entry has been made and that the creation of a hero will be exited. If the user chooses no, then the method should be ended also. If the user chooses yes or there is no current hero i.e. null) then Ask the user which hero type they would like to create 1 Archer 2. Warrior, 3. Mage. Use the readint method to validate the input and handle if an exception is thrown from this method appropriately. If a valid value is entered instantiate a archer, warrior or mage based on what was set it to the Example Executions: red after Satisfaction display Hero method: If the hero does not exist print an appropriate message, else call the appropriate method to display information about the hero. Example Executions: Type: Warrior Health: 20 Level: Experience: Max Health: 189 Potions Small: Medium: Large: No hero exists 0 II. 100 Assignment 1 - due: Tuesday 27th of April 2021 at 10:00 am p. 7 of 10 healHero method: If the hero does not exist print an appropriate message, else if hero is a mage, ask the user if they want to use Magic Heal (Use readyNChar as before) and if so use magicHeal on the hero, Else if the user selects healHero method: of the hero does not exist print an appropriate message, else if hero is a mage, ask the user if they want to use Magic Heal (Use readyNChar as before) and if so use magic Heal on the hero, Else if the user selects no, or the hero is a archer or warrior then, ask the user what size potion they want to use 1 small 2 medium, 3.lage (use readint as before), and use Potion on the hero, if the potion is available then print "Potion Consumed'else print 'This potion is not avaliable' Example Executions: There of potion would you like to use? 1. Small Medium Large Inter choice >> 1 Potion Consumed hat sie of potion would you like to use? 1. Saall 2. Medium 6. Large Enter choice >> 3 This potion is not avaliable Do you want to use Magic Heal? Magic Heal Used Do you want to use Meyle Heal? Medite of potion would you like to use? 1. Medium 1. Large Enter choice >> 2 Potion Consud damageHero method: if the hero does not exist print an appropriate message, else ask the user how much damage they want to inflict the hero in the range of (0 - 100000) (use readint as before), then use takeDamage on the hero. If the heros health goes below, inform the user and set hero to null. Example Executions: How much do you want to danage the hero ? Hero has taken danage How much do you want to danage the hero (8 - 188880)? Hero has fainted You will need a new Hero! giveHeroExperience method: if the hero does not exist print an appropriate message, else ask the user how much experience they want to give the hero in the range of (0 - 100000) (use readint as before), then use gainExperience on the hero. If the hero levels up let the user know with a message. Example Executions: How much expierents do you want to give the hero (8-1800887 Here has leveled up! 17 How much expierence do you want to give the here ce Enter choice >> 10 Here has recieved some experience
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