SA-1, due Sep 23

Assignment

In class we saw a Counter that would increment up to a given limit, and then start over at 0 when that limit was reached. I said that this would be a useful part of a digital watch or timer.

This assignment is to write a DigitalTimer class that creates objects that are digital timers with two fields: hours and minutes. This timer represents 24-hour time, so the hours should take on values 00 through 23 and the minutes should take on values 00 through 59.

Your DigitalTimer class should make public the following two constructors and three methods. Note that two of these have preconditions. A precondition is something that you may assume about the parameters. You need not test for it.

/** * Creates a timer initialized to 00:00 */ public DigitalTimer() /** * Creates a timer initialized to hours:minutes * Precondition: 0 <= hours <= 23 and 0 <= minutes <= 59 * * @param hours value for hours part of timer * @param minutes value of minutes part of timer */ public DigitalTimer(int hours, int minutes) /** * @return the time in hours:minutes format */ public String toString() /** * Increases the time by a minute, wrapping if necessary */ public void tick() /** * Sets the current time to hours:minutes. * Precondition: 0 <= hours <= 23 and 0 <= minutes <= 59 * * @param hours value for hours part of timer * @param minutes value for minutes part of timer */ public void set(int hours, int minutes) The private data in your DigitalTimer class should consist of two Counter objects, one to represent the hours and the other to represent the minutes. You should use most of the methods from the Counter class that we saw in class to implement the methods for the DigitalTimer class. Because methods of the Counter class do a lot of the work for you, none of the DigitalTimer methods should be longer than a few lines of code.

Note that it is not a problem that the tick() and set() methods appear in both the is the Counter and DigitalTimer classes. Java can tell which you mean by looking at the type of the object before the dot when the method is called.

Include the code for the Counter.java class and the TimerDriver.java class in your project along with the DigitalTimer class that you put into the file DigitalTimer.java. Running TimerDriver's main method will test the correctness of your DigitalTimer class.

Put your DigitalTimer.java file and a file containing the the output of TimerDriver.java (when in a project with your DigitalTimer.java code and my Counter.java) into a folder, zip them, and turn in the compressed file via Blackboard.