Question: Java code to implement a Clock class and utilizing a pre-written driver program to test your implementation. Here is a UML diagram for the Clock
Java code to implement a Clock class and utilizing a pre-written driver program to test your implementation. Here is a UML diagram for the Clock class: Clock - hr : Integer - min : Integer - alarmHr : Integer - alarmMin : Integer constructor Clock() - setHr( h : Integer ) : void - setMin( m : Integer ) : void - getHr() : Integer - getMin() : Integer - setAlarmHr( h : Integer ) : void - setAlarmMin( m : Integer ) : void - getAlarmHr() : Integer - getAlarmMin() : Integer + setTime( h : Integer, m : Integer ) : void + setAlarm( h : Integer, m : Integer ) : void + alarmSound() : Boolean + tick() : void + toString() : String Descriptions of each of the methods described in the UML can be found on the next page. Method Description of Task Clock() This is the constructor for the class. It should set the default time for the object to 00:00 using the setHr() and setMin() methods. It should also set the alarm to 00:00 using the setAlarmHr() and setAlarmMin() methods. This method is already written for you. setHr() This method is written for you already as a sample. Takes one parameter h and sets the hr field to that value if h is a valid hour (between 0 and 23 inclusive), otherwise set it to 0 . setMin() Takes one parameter m and sets the min field to that value if m is a valid minute (between 0 and 59 inclusive), otherwise set it to 0 . setAlarmHr() Takes one parameter h and sets the alarmHr field to that value if h is a valid hour (between 0 and 23 inclusive), otherwise set it to 0 . setAlarmMin() Takes one parameter m and sets the alarmMin field to that value if m is a valid minute (between 0 and 59 inclusive), otherwise set it to 0 . getHr() This method is written for you as a sample. Returns the value of the hr field. getMin() Returns the value of the min field. getAlarmHr() Returns the value of the alarmHr field. getAlarmMin() Returns the value of the alarmMin field. setTime() Takes two parameters h and m and uses setHr() and setMin() to set the time for the Clock object. setAlarm() Takes two parameters h and m and uses setAlarmHr() and setAlarmMin() to set the alarm for the Clock object. alarmSound() Returns a boolean value of true if the current time and the alarm time are equal. Return false otherwise. tick() This method takes no arguments and increments the object's time. It should add 1 to the current time, taking into account changing hours and end-of-day situations. toString() This method is already written for you and is used as you used it in the previous lab. In the file Clock.java is the skeleton of the Clock class. Some of the methods have the basic code present, some methods are missing and need to be written from scratch. Most of the methods aside from tick() can be written in a few lines of code. tick() will likely be the lengthiest method to write. There are two files that you should download : Clock.java and Tester.java . Tester.java is the file that contains an implementation of a program that sets the time on a clock, sets an alarm and then ticks the clock for awhile to see if the alarm should sound. You can edit that file if you'd like to look at it. Tester.java will compile and run only if Clock.java is completed and compiles correctly. STOP! Have a lab assistant check off that your program runs satisfactorily. Enter current time, hours: 1 Enter current time, minutes: 23 Enter alarm time, hours: 23 Enter alarm time, minutes: 56 How many minutes should the clock run for? 2 The time is 01:23 The time is 01:24 Enter current time, hours: 13 Enter current time, minutes: 40 Enter alarm time, hours: 13 Enter alarm time, minutes: 50 How many minutes should the clock run for? 5 The time is 13:40 The time is 13:41 The time is 13:42 The time is 13:43 The time is 13:44 Complete the program in the file Clock.java Compiling and running the program Sample Run Sample Run Enter current time, hours: 13 Enter current time, minutes: 42 Enter alarm time, hours: 13 Enter alarm time, minutes: 42 How many minutes should the clock run for? 500000 The time is 13:42 BING BONG! BING BONG! Enter current time, hours: 14 Enter current time, minutes: 59 Enter alarm time, hours: 15 Enter alarm time, minutes: 3 How many minutes should the clock run for? 100230 The time is 14:59 The time is 15:00 The time is 15:01 The time is 15:02 The time is 15:03 BING BONG! BING BONG! Sample Run Sample Run Enter current time, hours: 14 Enter current time, minutes: 49 Enter alarm time, hours: 14 Enter alarm time, minutes: 48 How many minutes should the clock run for? 1400 The time is 14:49 The time is 14:50 The time is 14:51 The time is 14:52 The time is 14:53 ... (time running from 14:54 through next day's 14:03 omitted for brevity) ... The time is 14:04 The time is 14:05 The time is 14:06 The time is 14:07 The time is 14:08
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
