I would like to set and display a score that varies on how fast the correct answer was made. For example..a question would be answered for only a minute..and the score would be 20points for answering in the range of 1-10 seconds, 15points for answering in the range of 11-30 seconds, 10 points for answering in the range of 31-45seconds and 5points for the remaining time till it reaches 1minute. and no score for incorrect answers.

Thanks in advance for those who could help! :D

The Date class should help. It holds not just the date but also the time in mSecs. Its default constructor initialises it to the exact time it was created. Its getTime() method returns mSecs, so you can do this:

long start = new java.util.Date().getTime();
 // do whatever
 long end = new java.util.Date().getTime();
 System.out.println("Watever took " + (end - start)  + "mSec");

If you want to interrupt the user after 1 minute and stop waiting for him to reply, then that's another problem, involving multiple Threads. Do you need/want to go there?

Edited 6 Years Ago by JamesCherrill: n/a

The Date class should help. It holds not just the date but also the time in mSecs. Its default constructor initialises it to the exact time it was created. Its getTime() method returns mSecs, so you can do this:

long start = new java.util.Date().getTime();
 // do whatever
 long end = new java.util.Date().getTime();
 System.out.println("Watever took " + (end - start)  + "mSec");

If you want to interrupt the user after 1 minute and stop waiting for him to reply, then that's another problem, involving multiple Threads. Do you need/want to go there?

Hmm. maybe i'll go for multiple threads if that is what i need..can you explain about it?

OK, lets have a look at that. In the meantime, you will still use the method I showed above to calculate the elapsed time & thus your points.
What form of user input are you using?

im using a text field..it will get the answer..and if it matches the correctanser, it will invoke the calculation for the score..but the user will be given only a minute to answer..and it will move forward to another question after a minute and so on..

thanks i'll be reading this first and ask again if there's more that i need to clarify. :)

This question has already been answered. Start a new discussion instead.