Create a RobotFriend class. RobotFriend is a new toy just on the market. Copy the starter class and the tester from Codecheck. A RobotFriend has a name and replies to various commands Provide a constructor that takes the name of the RobotFriend as a parameter. Remember that a constructor has the same name as the class. What does the class need to remember? That is the instance variable. Provide the following methods: public String getName() gets the name of this RobotFriend public void setName(String newName) sets a new name for this RobotFriend public String whatDoYouNeed() returns a string consisting of name + " needs a battery charge" where name is the name of this RobotFriend (which was supplied in the constructor) public String doCommand(String whatToDo) returns a string consisting of "Your friend " + name + " does not " + whatToDo where name is the name of this RobotFriend and whatToDo is the parameter

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

Create a RobotFriend class. RobotFriend is a new toy just on the market. Copy the starter class and the tester from Codecheck. A RobotFriend has a name and replies to various commands

Provide a constructor that takes the name of the RobotFriend as a parameter. Remember that a constructor has the same name as the class.

What does the class need to remember? That is the instance variable.

Provide the following methods:

  • public String getName() gets the name of this RobotFriend
  • public void setName(String newName) sets a new name for this RobotFriend
  • public String whatDoYouNeed() returns a string consisting of name + " needs a battery charge" where name is the name of this RobotFriend (which was supplied in the constructor)
  • public String doCommand(String whatToDo) returns a string consisting of "Your friend " + name + " does not " + whatToDo where name is the name of this RobotFriend and whatToDo is the parameter

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

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