I am making a program that demonstrates artificial intelligence.
I have modelled the behaviour of a pet animal e.g. it feeds, exercises and sleeps etc etc.
At the moment it is turn based i.e. each time you send a command e.g. feed, it will update the statistics and then display them.
What I need is to have it so that if no command is input after say 9 seconds, it will automatically sleep and therefore statistics change accordingly - exercise goes down and boredom goes up etc.
Please give me hints on how I would either make a method that controls the timing of the program or how to make the method below call another method if no command in 9 seconds.
If any more code from my program is needed then just say.
Thank you
public String male(String male)
{
Scanner command = new Scanner(System.in);
String commandIssued = command.nextLine();
if(male.equals("yes"))
{
if(commandIssued.equals("exercise"))
{
exercised("exercise");
}
else if(commandIssued.equals("feed"))
{
feeding("fed", "male");
}
else if(commandIssued.equals("excite"))
{
excite("excite", "male");
}
else if(commandIssued.equals("exercise feed"))
{
volatility++;
exercised("exercise");
feeding("fed", "male");
}
else if(commandIssued.equals("exercise excite"))
{
volatility++;
exercised("exercise");
excite("excite", "male");
}
else if(commandIssued.equals("feed excite"))
{
volatility++;
feeding("fed", "male");
excite("excite", "male");
}
else if(commandIssued.equals("exit"))
{
System.exit(1);
}
else if(no action in 9 seconds)
{
sleep();
}
}
return null;
}