Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( DO NOT USE WHILE ( TRUE ) ) We are going to get our Robot working. The Robot blueprint has two instance variables, the
DO NOT USE WHILE TRUE We are going to get our Robot working. The Robot blueprint has two instance variables, the robot name and the current battery level. The class should have the following methods they must have
the signature above:
A constructor that has two parameter a String containing the name of the Game and a int that sets the current battery level.
An empty constructor
A toString
A method performTask that takes in the task name and the amount of battery required for that task. The method removes that much battery if it is available. If not, it indicates so and does not complete the task.
A method rechargeBattery that just resets the level to
A method isBatteryLow that is a boolean. Used to check the battery level.
Getters and setters at the bottom
Write a RobotDriver program that creates a Robot object and then loops DO NOT use a whiletrue
Shows a menu see sample output
If the user chooses ask for the task and the amount of battery needed. Call the performTask method on the object. Check to see if the battery is low using the isBatteryLow and if it is let the user know it is low do not automatically recharge it
If the user chooses call the rechargeBattery method.
End the loop when the user chooses
Sample outputs:
Robot Simulator
Enter the robot's name: Bolt Man
Enter the initial battery level :
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Enter the task to perform: eat
How much battery does the task take
Bolt Man is performing the task: eat
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Enter the task to perform: run
How much battery does the task take
Cannot do that. Recharge the batteries first.
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Enter the task to perform: jog
How much battery does the task take
Bolt Man is performing the task: jog
Bolt Man Your battery is low! Recharge now.
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Bolt Man is recharging battery. Please wait...
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Enter the task to perform: walk the dog
How much battery does the task take
Bolt Man is performing the task: walk the dog
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Enter the task to perform: feed the dog
How much battery does the task take
Cannot do that. Recharge the batteries first.
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Enter the task to perform: feed the dog
How much battery does the task take
Bolt Man is performing the task: feed the dog
Bolt Man Your battery is low! Recharge now.
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Enter the task to perform: sleep
How much battery does the task take
Cannot do that. Recharge the batteries first.
Bolt Man Your battery is low! Recharge now.
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Bolt Man is recharging battery. Please wait...
Bolt Man the robot currently has a battery level of
Select an action:
Perform a task
Recharge the battery
Exit
Enter your choice :
Bolt Man the robot currently has a battery level of
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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