Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CS161 Introduction to Computer Science II Lab 2 - Party Points: 35 Goals By completing this Lab, you will review and gain experience using
CS161 Introduction to Computer Science II Lab 2 - Party Points: 35 Goals By completing this Lab, you will review and gain experience using UML diagrams, arrays, random numbers, object aggregation, user interaction via the console, and basic testing. Create an Eclipse project named "Lab2_FirstNameLastName". (22 pts) Implement an application with the following description: Create three classes: Hero, Party, and PartyTest. CS161 Introduction to Computer Science II 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 -hClass: String -level: int -experience: int -MAX LEVEL: int -LEVELS: int[10] Methods +Hero (name: String) Contains the name of the Hero Contains the class of the Hero (Be careful, class is a java keyword!) Contains the level of the Hero +toString() Contains the experience of the Hero Constant static int containing the max level possible. Set it to 10. +Any accessor methods you need +Any mutator methods you need +setRandomLevel() :void :String 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. +gainExperience (experience: int) :void Set the name to given value and set class to empty String, level to 1, and experience to 0. Return the name, class, or level. Set the name, class, or level. Set the level to a random level between 1 and 10. Increase the experience of the Hero. If the experience reaches or passes the maximum for the Hero's current level, increase the level by 1, reset experience to 0, and add any "leftover" experience. 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. CS161 Introduction to Computer Science II The Party class contains an array of Hero's to manage the current party. Implement the Party class according to the following UML diagram: Data fields -Heroes: Hero[3] Methods +Party() +addHero(index: int, hero: Hero) :void +removeHero(index: int) :Hero +getHero(index: int) :Hero +gainExperience(experience: int) +toString() :String Party Contains the Hero's in the current party. Implement PartyTest class with the following description. The PartyTest class has the main method that must do following: O O Initialize the empty Hero array to hold 3 Hero's. Add a Hero to the current party at the given index. If there is an existing Hero at the index, replace it. Remove and return the Hero from the given index (set the array index to null to "remove"). Return the Hero of the desired index. Increase the experience of all the Hero's in the Party. Hint: Use each Hero's gainExperience method Print out the current Party's data. Hint: Use each Hero's toString method. 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. If the user enters an invalid class, inform them to try again. Set the class of each Hero. CS161 Introduction to Computer Science II Test the various methods of the Party and Hero classes. Here are some examples: Use the setRandomLevel method on one of the Hero's. O O Put 3 Hero's in the party. O Sample Output Give them some experience and make sure they are leveling up properly (print their data to prove it). Mix up the party by swapping in the unused Hero. Give the party some more experience and print the party's data again. 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 experience Tyrone the thief is level 3 with 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! CS161 Introduction to Computer Science II 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 Submit: Submit the Eclipse project folder containing source code and all associated class files by the due date. All source code should be properly documented.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a basic outline of how you could implement the three classes described Hero Class Attributes n...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