Let’s assume you are creating a game where multiple players are involved. You will create a Player class that will allow you to later create Player objects. Each player will need a name, a health level, a super power, and number of lives remaining. In your Player class we need the following: Four private data members: name (a String) health (an int) power (a String) lives (an int) Three Constructors: A constructor that has no parameters and sets name to “No Name”, health to 100, power to “Nothing”, and lives to 3.A constructor that takes in two parameters – a String for the name and a String for the power. The health variable should be set to 100 and the lives variable should be set to 3 by default. A constructor that takes in all four parameters and sets them. Accessors and Modifiers (8 total): Create an accessor/getter for all four private data members. Create a modifier/setter for all four private data members. toString() method Create a toString() method that neatly displays the data for each object. For example, it might be in the form of: Player’s Name: Batman Player’s Current Health: 50 Player’s Power: Fly Player’s Remaining Lives: 1 Once your Player class is complete with the items requested above, create a new java file and name it Game. Include a main method. This will be the class that can execute. It will utilize the Player class to create Player objects. Make sure your Game file and your Player file are in the same folder. In this Game class, in the main method, we will write code to test our Player class and make sure everything was defined properly. I want to see the following in the main method of our Game class: Create an array of Player objects that can hold exactly 5 objects. (This game only allows 5 people to play at a time.) Fill the array up with the following: (The following will probably NOT be in a loop.) The first Player object in the array (index 0) will utilize the constructor that has zero parameters. This player is a special player who will input all of their information later. The second and third Player objects in the array will utilize the constructor that has two parameters. You will need to pass in the name and the power for each of these two objects. The fourth and fifth Player objects in the array will utilize the constructor that has four parameters. You will need to pass all four pieces of information in for each object. Next, ask the user for each piece of information for the first Player object. Use the modifier/setter methods to give the first Player the name, health, power, and number of lives that the user enters. (Please utilize the four setter methods to set this information for the first Player object.) Finally, inside of a loop, call the toString() method so that a description prints for every object. Do not just type out 5 print statements. That is not efficient or scalable. in java

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

Let’s assume you are creating a game where multiple players are involved. You will create a Player class that will allow you to later create Player objects. Each player will need a name, a health level, a super power, and number of lives remaining. In your Player class we need the following:

Four private data members:

name (a String)

health (an int)

power (a String)

lives (an int)

Three Constructors: A constructor that has no parameters and sets name to “No Name”, health to 100, power to “Nothing”, and lives to 3.A constructor that takes in two parameters – a String for the name and a String for the power. The health variable should be set to 100 and the lives variable should be set to 3 by default. A constructor that takes in all four parameters and sets them.

Accessors and Modifiers (8 total): Create an accessor/getter for all four private data members. Create a modifier/setter for all four private data members.

toString() method

Create a toString() method that neatly displays the data for each object.

For example, it might be in the form of:

Player’s Name: Batman

Player’s Current Health: 50

Player’s Power: Fly

Player’s Remaining Lives: 1

Once your Player class is complete with the items requested above, create a new java file and name it Game. Include a main method. This will be the class that can execute. It will utilize the Player class to create Player objects. Make sure your Game file and your Player file are in the same folder.

In this Game class, in the main method, we will write code to test our Player class and make sure everything was defined properly. I want to see the following in the main method of our Game class: Create an array of Player objects that can hold exactly 5 objects. (This game only allows 5 people to play at a time.)

Fill the array up with the following: (The following will probably NOT be in a loop.)

The first Player object in the array (index 0) will utilize the constructor that has zero parameters. This player is a special player who will input all of their information later.

The second and third Player objects in the array will utilize the constructor that has two parameters. You will need to pass in the name and the power for each of these two objects. The fourth and fifth Player objects in the array will utilize the constructor that has four parameters. You will need to pass all four pieces of information in for each object.

Next, ask the user for each piece of information for the first Player object. Use the modifier/setter methods to give the first Player the name, health, power, and number of lives that the user enters. (Please utilize the four setter methods to set this information for the first Player object.)

Finally, inside of a loop, call the toString() method so that a description prints for every object. Do not just type out 5 print statements. That is not efficient or scalable.

in java

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning