Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions