• Post Reply Bookmark Topic Watch Topic
  • New Topic

sample program which will prompt the user to enter the message along with the time, a  RSS feed

 
sudha sudha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which will prompt the user to enter the message along with the time, and when it matches the System time it will retrieve the message and display it to the user.

thanks in advanced
 
Ramamoorthy Periasamy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might use java.util.Scanner
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what your question is. If you're asking how to write a program like that, then show us where you're stuck, and I'm sure we can help out.

Please continue this discussion in the Java in General (beginner) forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sudha sudha",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, you can get the system time with...

System.getTimeMillis();

and you can scan the user's input with the Scanner in

java.util.Scanner;

but remember, if you get the user's time in seconds....

1 second = 1000 milliseconds...

and thats the value you'll need to be looking for if the user enter's

1 sec, and if they enter 1 min.

then you'll need to look for 60,000;

but you'll need to get a start time for the system...

and after the scan of the input....then say

if(startTime + System.currentTimeMillis() == userInput)
System.out.print("Time Reached!!");

because the system initially took time to execute the question...

Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or an easier way would be to pause the thread...

enter a time: 2 // seconds

enter a message to be displayed: times up!

in the main you could do this...



the system will sleep (pause) for 2 seconds..

then print to the screen "times up!"

Justin
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Justin Fox about Thread(sleep). But you forgot to put in the Exception handling. Thread.sleep() declares a checked Exception, so you have to code itAnd the sleep method is static, so you don't need a Thread object.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!