Some of the hot toys lately have been robots. Consider one particular robot that can walk and talk. Its "conversation" consists of uttering one of several phrases chosen at random, such as "Hey, how's it going?" or "You look marvelous!"
Specifications: You should break the day into at least four time blocks. For each time block, there should be at least three different phrases that the robot might ramdomly choose among. At least one or two of those should be time-specific (like "Let's go eat lunch!"). Others can be more generic. Generic phrases can be used in multiple time blocks if you want. For example, you could decide to include "Hey, how's it going?" as a possible phrase in every time block if you want. On the other hand, time-specific phrases should not be among the possibilities in inappropriate time blocks. You will have to write your randomly-chosen phrase to the console, since you don't have an actual robot to program.
To begin, download the Talking Robot program.
The code you add should go into the main
method of the Robot.java
file in the Code
folder. Currently, the clock on the robot is malfunctioning,
so when you push the button to get the current time of the day and a message,
you will get a random time. Use the Random class to get a random number between
0 and 23 to represent what hour of the day it is. Print a message telling the
user the "current" time.
Next, modify your program by printing a simple phrase that depends on the "current" time block. For example, if one of your time blocks is 3am - 10am, you might want to just print "Good morning" when the current time falls in that block. Once you have that code written to your satisfaction, replace the single phrase with a block of code that prints one of several phrases depending on a random number.
Be sure to edit the comments in the Robot.java
file as appropriate,
including the class documentation comments at the top of the file. The class
documentation comments should describe the purpose and behavior of your main
class from a user's perspective. Focus on what the program does, rather
than how it does it. Include your name and the date as well as the names
of anyone from whom you received help. Providing proper documentation is an
important step towards writing well-structured and reusable programs.
Note: Using a random number to represent the current time makes testing easier, because otherwise you would have to test it at various times during the day. You could improve the program to actually make use of the current time by using the
Calendar
class. To get aCalendar
object whose fields are initialized with the current date and time, you would need a statement such as:To get the current hour of the day, you would need to use a statement such as:Calendar rightNow = Calendar.getInstance();
This returns an integer between 0 and 23, where 0 represents the hour between midnight and 1 AM, 12 represents the hour between noon and 1 PM, 23 represents the hour between 11 PM and 12 midnight, and so on.)int timeOfDay = rightNow.get(rightNow.HOUR_OF_DAY);