Lab: Talking Robot

Using If-Else and Random Numbers


This lab should be done individually. It is okay to get help from the TAs and/or the instructor if you get stuck, but you should try to do it on your own first.

Tip: You should get into the habit of making backup copies of your work.


 

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!"

Improved Choice of Phrases based on Time of Day:

Suppose the robot also has a clock, and can be used as an alarm clock. You have been hired by the makers of the robot to help create a new and improved version. Your focus will be to improve its conversational skills by making its choice of phrases depend on the time of day. For example, if it's before 10 am, it might say "Good morning!", "This is way too early for me!", or "Hey, how's it going?" If it's close to lunch time, it might say, "I'm hungry. Let's go eat lunch.", "I'm never going to finish my homework before class!", or "You look marvelous!"

Specifications: You should break the day into at least four time blocks. Time blocks are defined by hours of the day: an hour is 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. For each time block, there should be at least three different phrases that the robot might randomly 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.

Design: For this program, you will use 3 classes: an application class containing the main method, a class representing robots, and a class representing a clock. The main method will construct a robot and ask it to utter a time-appropriate random phrase. The robot will ask the clock for the current hour of the day in order to decide on possible phrases to use. The class diagram below shows the three classes and shows that the RobotLabApp application class uses an object (or more than one objects) of the Lab2TalkingRobot class, and that robot objects use the Clock class. (You may use the same class names as the diagram, although you do not need to.)

Class Diagram for Talking Robot Lab

Before starting to implement your talking robot, take a few minutes to plan which time blocks you are going to use and identify at least one phrase for each time block.

Implementation: One common process for developing software is to develop it in small increments, testing the program at every step to ensure that you have a working program all along the way.


When you complete the lab, you can start work on Programming Project #2 (due at the beginning of Lab 3).