CSC15 Lab 8 Due in one week For this lab you will write a class that will form the computational part of a program that displays a countdown timer as demonstrated in class. The most important function of the class will involve a nested loop that decrements the timer appropriately. You will also be writing a class and further practice oop skills. 0. download the file "timergui.java" from the class homepage. This is my part of the program. DO NOT TOUCH THIS FILE AT ALL! Just make sure it's in the same directory as your program. 1. You are to produce a file called timer.java, with a class timer. You will not be writing a main function (that's in my code). 2. Using the following code as template, define the class. This class needs to have 4 variables (m1,m0,s1,s0) because the graphical display shows the time using four separately managed digits. The minute value will consist of digits m1 and m0, with m1 ranging from 0 to 5 and m0 ranging from 0 to 9, and similarly for s1 and s0. 3. One of the variables in the timer class you'll define (see skeleton below) will be a variable called "gui", which is a link to the graphical display component of the program. This object has two methods you can call: void displayUpdate(int m1, int m0, int s1, int s0) and void delay(int approx_millesconds) have been predefined. The first one updates the graphical display with the parameters passed to it. The second one delays by a number of milliseconds. The exact time is approximate, so you'll NEED TO adjust it so that your timer synchronizes with real time. For example: gui.displayUpdate(3,4,2,0); will display 34 minutes and 20 seconds gui.delay(1000); will delay NOT EXACTLY 1000 milliseconds. See additional instructions in comments below. 4. After you get the basic count-down timer working, following the instructions and get the reset button to work. Sketch the nested loop on paper before coding. /* Copy the following into a file called timer.java, and follow instructions. */ class timer extends Thread // a Thread is a concurrently running program. { private int m1, m0, s1, s0; // minute and second values private mywindow gui; // (link to graphical display in timergui.java) // you'll be defining other variables later. public timer(int a, int b, int c, int d, mywindow g) // constructor { m1 = a; m0 = b; s1 = c; s0 = d; gui = g; } // constructor /* Here is the principal function you'll need to define. Don't change the name - it must be called 'run'. It should count down from the values the user typed in towards zero using nested loops (4 levels). In the body of the innermost loop, you need to call displayUpdate and delay after updating the appropriate (s0) value. Think carefully and in a structured manner. figuring out how exactly to reset the numbers inside the loops can be tricky and you need to also experiment. Your function should terminate when all 4 values are zero. */ public void run() { } // run // see part II below: public synchronized void reset() { } } // end class timer /* To run the program, do the following: javac timergui.java javac timer.java java timergui PART II : THE RESET BUTTON This program actually uses a fairly advanced technique called multi-threading. The two parts of the program, the graphical display and your nested loop, are actually running simultaneously! This is why your class "extends Thread". Without this being the case, you will not be able to get the reset button to work. To make reset work, you first must define INSIDE the CLASS an additional 4 variables that are used to hold the ORIGINAL values of the time when the timer object is first created (i.e. when the constructor was called). You then need to modify your constructor to set the initial values of these variables to be the same as m1 m0 s0 s1 (you won't need additional parameters for the constructor - think about what you're doing). You also need to add the following definition: private boolean running. And in your constructor function, you need to add the line: running = false; Now, complete the reset function of the timer class: public synchronized void reset() { // this function should set running to false, set m1, m0, s1 and s0 back // to their original values, and call gui.displayUpdate to set the // display appropriately. } Are you done yet? Not quite! Your while loop doesn't know when to stop! You need to modify the run function as follows: At the very begining of the function, you need to set running = true. Then, you need to modify ALL your while loops so that they will terminate whenever running is set to false. That's easy, just add the condition while (... && running) to the continuation condition of each of your while loops. If you want, you can look at timergui.java to see how things really work. */