Answered step by step
Verified Expert Solution
Link Copied!

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 100
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 while(true)!
Shows a menu (see sample output)
If the user chooses 1, 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 2, call the rechargeBattery() method.
End the loop when the user chooses 3.
Sample outputs:
Robot Simulator
---------------
Enter the robot's name: Bolt Man
Enter the initial battery level (0-100): 100
Bolt Man the robot currently has a battery level of 100
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 1
Enter the task to perform: eat
How much battery does the task take
45
Bolt Man is performing the task: eat
Bolt Man the robot currently has a battery level of 55
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 1
Enter the task to perform: run
How much battery does the task take
90
Cannot do that. Recharge the batteries first.
Bolt Man the robot currently has a battery level of 55
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 1
Enter the task to perform: jog
How much battery does the task take
37
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 18
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 2
Bolt Man is recharging battery. Please wait...
Bolt Man the robot currently has a battery level of 100
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 1
Enter the task to perform: walk the dog
How much battery does the task take
39
Bolt Man is performing the task: walk the dog
Bolt Man the robot currently has a battery level of 61
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 1
Enter the task to perform: feed the dog
How much battery does the task take
70
Cannot do that. Recharge the batteries first.
Bolt Man the robot currently has a battery level of 61
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 1
Enter the task to perform: feed the dog
How much battery does the task take
60
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 1
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 1
Enter the task to perform: sleep
How much battery does the task take
10
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 1
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 2
Bolt Man is recharging battery. Please wait...
Bolt Man the robot currently has a battery level of 100
Select an action:
1. Perform a task
2. Recharge the battery
3. Exit
Enter your choice (1-3): 3
Bolt Man the robot currently has a battery level of 100
image text in transcribed

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

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions

Question

What is Ohm's law and also tell about Snell's law?

Answered: 1 week ago