Question: Code a class called Fighter with instance variables as: name: maximum length of 15 characters alive: either true (alive) or false (dead) health: 5 levels

Code a class called Fighter with instance variables as:

name: maximum length of 15 characters

alive: either true (alive) or false (dead)

health: 5 levels of health with 1 (MIN) as poor health and 5(MAX) as good health

At class level there are two static constants called MIN and MAX health. The class shall consist of one parameter constructor that will set the name of fighter using its setter and set the values of alive and health variables as false and MIN, respectively.

Write setters (mutators) for name and alive instance variables.

Code a zero-parameter method called healthUpdate() which will increment the health by 1 level. It should return a Boolean that indicates if the health is updated or not.

Code a toString() method that prints the current state of Fighter Class.

Code the main method which will instantiate a Fighter object with name Shawn. Call the setter of the alive instance variable and set the value to true. Next, call the healthUpdate() method 5 times and then display the state of object using toString() method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!