public class TalkingRobot
{
private Clock clock; // used by getTime and sayAPhrase
private Random generator; // used by sayAPhrase and respondTo
public void sayAPhrase()
{
int hr = this.clock.getHour();
int randNum;
if ( hr < 12 )
{
randNum = this.generator.nextInt(2);
if ( randNum == 0 )
System.out.println("Good morning!");
else
System.out.println("Have a great day!");
}
else
{
randNum = this.generator.nextInt(3);
if ( randNum == 0 )
System.out.println("Hi! How are you?");
else if ( randNum == 1 )
System.out.println("Half the day is gone!");
else
System.out.println("Today has been great!");
}
}
}
|