I am working on an offline console based quiz application in Java, and I want a timer of 30 seconds for each question.
In order to answer a question, the user has 4 choices, 1 to 4, and the user can skip the question by pressing 0. I tried Executor service method, but I want that if the user answers the question, the next question should come immediately after pressing the key.
Using Executor service will wait till the 30 seconds are over. Here is the code to this I have to add the timer.
//displaying questions to the user and respective actions
for(int i=0;i<fullText.length;i++)
{
question=new String[6];
question=fullText[i].split(",");
commit=0;
made=false;
br=new BufferedReader(ir);
while(commit!=1)
{
try
{
System.out.print("\n Question No. "+(i+1));
System.out.print("\n ------------------");
System.out.print("\n "+question[0]);
System.out.print("\n Option 1 -->"+question[1]);
System.out.print("\n Option 2 -->"+question[2]);
System.out.print("\n Option 3 -->"+question[3]);
System.out.print("\n Option 4 -->"+question[4]);
while(made!=true)
{
System.out.print("\n YOUR ANSWER[1-4] (Type 0 to Skip) : ");
String opt=br.readLine();
if(isNum(opt)==false)
{
System.out.println("Invalid input. Your choice should be an integer only...!");
made=false;