Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sleep if no action in given amount of time

807607Nov 3 2006 — edited Nov 6 2006
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;
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 4 2006
Added on Nov 3 2006
13 comments
197 views