I am new to java and i have a project about making a quiz with a timer, but that's not what i was going to ask since i am trying my best to make this project on my own, but this "static" error is something that i think that is hindering me from getting what i wanted from my code, i tried googling many ways to program what i wanted to do and this is the code that i ended up making, just dont mind the logic or my code, its just my code is full of static, i tried removing them all except the one from my main method, but i only get errors out of it, please help me or guide me what do i have to do to remove static. thank you
import java.util.Timer;
import java.util.TimerTask;
import java.util.Scanner;
import java.io.IOException;
public class q2 {
static int seconds = 0;
static Scanner a=new Scanner(System.in);
static Timer timer = new Timer();
static int number = 1;
static int score = 0;
public static void mema(){
TimerTask task = new TimerTask ()
{
public void run()
{
seconds++;
System.out.print(seconds);
}
};
timer.schedule(task,1000,1000);
}
public static void tanong1(String... args)throws IOException,InterruptedException
{
System.out.println("");
System.out.printf("%72s\n","QUIZ FOR PHILIPPINE HISTORY");
System.out.println("");
System.out.printf("%64s\n","Question #1");
System.out.println("");
System.out.println("\t\t\t\t\t WHO DISCOVERED PHILIPPINES?");
System.out.println("\n\t\t\t\t\t\tA. Fernando Magellan");
System.out.println("\t\t\t\t\t\tB. Ferdinand Megallan");
System.out.println("\t\t\t\t\t\tC. Ferdinand Magellan");
System.out.println("\t\t\t\t\t\tD. Fernando Poe");
System.out.println("\n\t\t\t\t\t\tTYPE YOU ANSWER HERE: ");
char sagot1 = a.nextLine().charAt(0);
switch (sagot1)
{
case 'B':
case 'b':
score++;
seconds=30;
System.out.print("You are CORRECT!");
Thread.sleep(3000);
break;
default:
System.out.print("You are WRONG");
seconds=30;
Thread.sleep(3000);
break;
}
}
public static void tanong2(String... args)throws IOException,InterruptedException
{
System.out.println("");
System.out.printf("%72s\n","QUIZ FOR PHILIPPINE HISTORY");
System.out.println("");
System.out.printf("%64s\n","Question #2");
System.out.println("");
System.out.println("\t\t\t\t\t WHO DISCOVERED PHILIPPINES?");
System.out.println("\n\t\t\t\t\t\tA. Fernando Magellan");
System.out.println("\t\t\t\t\t\tB. Ferdinand Megallan");
System.out.println("\t\t\t\t\t\tC. Ferdinand Magellan");
System.out.println("\t\t\t\t\t\tD. Fernando Poe");
System.out.println("\n\t\t\t\t\t\tTYPE YOU ANSWER HERE: ");
char sagot2 = a.nextLine().charAt(0);
switch (sagot2)
{
case 'B':
case 'b':
score++;
seconds=60;
System.out.print("You are CORRECT!");
break;
default:
System.out.print("You are WRONG");
seconds=60;
break;
}
}
public static void main(String... args)throws IOException,InterruptedException
{
mema();
while(seconds<=5){
tanong1();
}
while(seconds<=60||seconds>=6){
new ProcessBuilder("cmd","/c","cls").inheritIO().start().waitFor();
tanong2();
}
}
}
this is the error that i am getting in case i remove the static on my seconds variable error: non-static variable seconds cannot be referenced from a static context. i just want to know what do i have to do, thank you in advanced.