No matter how hard I try to fix this code it doesn't seem to want to work. I initially read the instructions and did everything like it said then when I clicked verify I am now being told I need to add Thread.sleep(3500); to the main method.
I'm not sure how to check the time from the main method. This is the first task that I think I am going to skip for now.
I can get the output the way that this task is asking, but it wants me to check the time in the main method some how. Any tips/explanation would be useful thanks. :)
package com.codegym.task.task16.task1617;
public class Solution {
public static volatile int numSeconds = 4;
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
try {
int count = 0;
while (!this.isInterrupted() && numSeconds > 0) {
System.out.print(numSeconds + " ");
Thread.sleep(1000);
numSeconds--;
count++;
}
if (count > 3) {
this.interrupt();
System.out.println("Interrupted!");
} else {
System.out.println("Go!");
}
} catch (InterruptedException e){
e.printStackTrace();
}
}
}
}