Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with writing this Java program. Write a hero class (Hero. java) that could be used in a role playing game. A hero

I need help with writing this Java program.

image text in transcribed

Write a hero class (Hero. java) that could be used in a role playing game. A hero has a name, an amount of health, an amount of mana (magic power) and can carry a limited number of items to help him or her on their quest. Your class should have data fields as follows: name - self-explanatory? health - an integer number between 100 (full health) and 0 (expired/deceased) max_items - the maximum number of items that the hero can carry at one time items - a list (ArrayList of Strings?) of items currently in the hero's possession. Think of this as the hero's backpack of holding. Once this value is set, it cannot be changed. The class should define the following methods: -Constructor (argumented): This constructor should allow for two arguments - a name and a number of items. The initial health value for a hero should be 100. A new hero should not be carrying any items but should have an empty list ready to accept items later on. If the maximum items is greater than 10 or less than 0 throw an IllegalArgumentException (look back in the book if you need a reminder). -Constructor (default): This constructor should allow for zero arguments. The initial health value 100. The hero's name should be "Anonymous" and they should have a limit of 2 items in their backpack. -inventory (): This method takes no arguments and returns (not simply print) a String representation of the items that the hero is currently carrying. If the hero is carrying nothing then a message should be displayed. -take(): This method should take one argument - the name of an item that the hero is adding to their inventory. The hero can only "take" an item if they are carrying less than their maximum number of items. If the hero is at their maximum carrying capacity, print an appropriate message. - drop(): This method should take a single argument - the name of an object the hero would like to remove from their inventory. If the user is not currently carrying the requested item then print an appropriate message, otherwise remove the item from inventory. - take Damage (): This method takes a single integer argument and subtracts that amount from the hero's health. It the resulting hero health would be less than zero, set the health to zero. - heal (): This method takes a single integer argument and adds that amount from the hero's health. It the resulting hero health would be greater than 100, set the health to 100. - toString (): write a proper toString method that will display the current state of a hero. Write a tester class (HeroTester. java) that tests your hero class. Create a hero object using the argumented constructor and create another one the default constructor and print their initial state. Test your take(), drop(). inventory(). takeDamage() and heal() methods on one of your heroes to show that all of the methods work as advertised above. Hard-code names and objects from your own imagination (be creative but not insulting or derogatory) Show your heroes' final state before exiting the program

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

Students also viewed these Databases questions

Question

Explain the Neolithic age compared to the paleolithic age ?

Answered: 1 week ago

Question

What is loss of bone density and strength as ?

Answered: 1 week ago

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago

Question

=+ Are there closed-shop requirements or practices?

Answered: 1 week ago