Question: I need help with this java problem - have most of the stuff working but a few things (I explain on the bottom in bold)
I need help with this java problem - have most of the stuff working but a few things (I explain on the bottom in bold)
The Hero class contains data related to a Hero in a video game. Implement the Hero class according to the following UML diagram:
Hero Data fields -name : String Contains the name of the Hero
-hClass: String Contains the class of the Hero (Be careful, class is a java keyword!)
-level: int Contains the level of the Hero
-experience: int Contains the experience of the Hero
-MAX_LEVEL: int Constant static int containing the max level possible
-LEVELS: int[10] Contains the experience of the Hero Constant static int containing the max level possible. Set it to 10. Constant static int array containing the numbers {5, 10, 15, 20, 30, 40, 50, 75, 100}. These are the experience amounts required to proceed from level 1 to 2 (5 experience), 2 to 3 (10 experience), etc. up to max level.
Methods
+Hero (name: String) Set the name to given value and set class to empty String, level to 1, and experience to 0.
+Any accessor methods you need Return the name, class, or level.
+Any mutator methods you need Set the name, class, or level.
+setRandomLevel() : void Set the level to a random level between 1 and 10. Increase the experience of the Hero.
+gainExperience(experience: int) :void If the experience reaches or passes the maximum for the Heros current level, increase the level by 1, reset experience to 0, and add any leftover experience.
+toString() :String Return a String containing the information about the hero such as name, class, level, experience. Make it easily readable when printed using newline and/or tab characters.
The Party class contains an array of Heros to manage the current party.
Party Data fields
-Heroes: Hero[3] Contains the Heros in the current party.
Methods +Party() Initialize the empty Hero array to hold 3 Heros.
+addHero(index: int, hero: Hero) : void Add a Hero to the current party at the given index. If there is an existing Hero at the index, replace it.
+removeHero(index: int) :Hero Remove and return the Hero from the given index (set the array index to null to remove).
+getHero(index: int) :Hero Return the Hero of the desired index.
+gainExperience(experience: int) Increase the experience of all the Heros in the Party. Hint: Use each Heros gainExperience method
+toString() :String Print out the current Partys data. Hint: Use each Heros toString method.
Test the various methods of the Party and Hero classes. Here are some examples: o Use the setRandomLevel method on one of the Heros.
PartyTest class with the following description. The PartyTest class has the main method that must do following: Create a Party object. Create a String array of valid class names. o You can decide what classes you allow the user to choose from. Create 4 or more Hero objects with names that you decide on. o You can think of your own names or have fun with a random name generator: https://www.name-generator.org.uk/ Using the console, list the available classes and ask the user to choose a class for each Hero. o If the user enters an invalid class, inform them to try again. o Set the class of each Hero. o Put 3 Heros in the party. Give them some experience and make sure they are leveling up properly (print their data to prove it). o Mix up the party by swapping in the unused Hero. Give the party some more experience and print the partys data again.
Example output:
The available classes are:
warrior
wizard
thief
clown
banker
Enter the class for Gumbledalf wizard
Enter the class for Bobby banker
Enter the class for Tyrone tyroneasaurus
That is not a valid class, but I admire your creativity.
Please enter a valid class for Tyrone thief
Enter the class for Ophelia warrior
Gumbledalf's level was randomized to 9
Gumbledalf was added to the party.
Bobby was added to the party.
Tyrone was added to the party.
The party gained 15 experience.
Bobby is now level 2!
Bobby is now level 3!
Tyrone is now level 2!
Tyrone is now level 3!
Party ------------------------------
Gumbledalf the wizard is level 9 with 15 experience
Bobby the banker is level 3 with 0 experience
Tyrone the thief is level 3 with 0 experience
Gumbledalf was removed from the party.
Ophelia was added to the party.
The party gained 45 experience.
Ophelia is now level 2!
Ophelia is now level 3!
Ophelia is now level 4!
Bobby is now level 4!
Bobby is now level 5!
Tyrone is now level 4!
Tyrone is now level 5!
Party ------------------------------
Ophelia the warrior is level 4 with 15 experience
Bobby the banker is level 5 with 10 experience
Tyrone the thief is level 5 with 10 experience
I'm using wizard, warrior, steve, bard, and thief as my classes and for my characters I'm using Alucard, Carmilla, Sypha and steve. My problem is I need help making the gain experience method, as well as making it work in the main method. I am also stuck on how to add my characters to a party - should I make them into an array? Any help would be appreciated - thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
