• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might use java.util.Scanner
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic