Clock clock = new Clock();
TalkingRobot robot =
new TalkingRobot(clock);
System.out.println("Timestamp: " +
robot.getTime());
robot.sayAPhrase();
String response;
response =
robot.respondTo("Do you want " +
"lunch?");
System.out.println("Response was: " +
response);
response =
robot.respondTo("What are " +
"local variables and " +
"instance variables?");
System.out.println("Response was: " +
response);
|
|
public class TalkingRobot
{
private Clock clock;
private Random generator;
public TalkingRobot(Clock aClock)
{
}
public String getTime()
{
}
public void sayAPhrase()
{
}
public String respondTo(String question)
{
int randNum = this.generator.nextInt(3);
if ( question.contains("lunch") )
{
if ( randNum == 0 )
return "Lunch... Not hungry yet.";
else if ( randNum == 1 )
return "Is it lunchtime already?";
else
return "I always like pizza.";
}
else
{
if ( randNum == 0 )
return "No idea!";
else if ( randNum == 1 )
return "Your guess is as good as mine.";
else
return "What do you think?";
}
}
}
|