6. In your homework2 directory create the program described below nsing python,
ID: 3593648 • Letter: 6
Question
6. In your homework2 directory create the program described below nsing python, java, shell or any other programming language you prefer. A 1-minute digital stopwatch shows a 10 second count down and then displays the word "FINISHED!" Create a program which shows this display. You do not have to incorporate a timer in it but if there will be a Spoint Extra Credit. a. (3pts) In the Word homework document you submit to Moodle, provide me with the absolute path to the program and · the command used to run it. Also, upload the source code to Moodle. b. (6pts) Write a program providing the following display: 50 40 30 20 10 FINISHED! I will grade this problem by running your program in your account and examine the source code implemented. Make sure I have laccess to the directory with your program and to all parent directories up to and including your home directory. If you use a shell script, be sure to make it executable. c. (3pts) If you use control statements and variables in your progranm.Explanation / Answer
Below is your program in java . Let me know if you have any trouble running it...
StopWatch.java
import java.util.Timer;
import java.util.TimerTask;
public class StopWatch {
static int interval;
static Timer timer;
public static void main(String[] args) {
int delay = 1000;
int period = 1000;
timer = new Timer();
interval = 60;
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
int timeLeft = setInterval();
if (timeLeft % 10 == 0 && timeLeft != 0)
System.out.println(timeLeft);
}
}, delay, period);
}
private static final int setInterval() {
if (interval == 1) {
timer.cancel();
System.out.println("Finished!");
}
return --interval;
}
}
Output
50
40
30
20
10
Finished!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.