I can tell I'm misunderstanding how the program is supposed to work, since I am only printing out "Interrupted!" instead of actually calling the interrupt() method, but I don't understand what the main method should do and what the purpose is of the main method calling Thread.sleep(3500)
package com.codegym.task.task16.task1617;
/*
Countdown at the races
*/
public class Solution {
public static volatile int numSeconds = 3;
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
//write your code here
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
//write your code here
long startTime = System.currentTimeMillis();
long endTime = startTime + 1;
long timeDifference;
for (int i = numSeconds; i >= 0 ; i--) {
endTime = System.currentTimeMillis();
timeDifference = endTime - startTime;
if (timeDifference > 3500) {
System.out.println("Interrupted!");
} else {
if (i == 0) {
System.out.println("Go!");
} else {
System.out.print(i + " "); }
try {
Thread.sleep(1000);
numSeconds--;
} catch (InterruptedException e) {
e.printStackTrace(); }
}
}
}
}
}