CSCI 180 (GOLDWEBER)
Spring 07: 1/29/07
Laboratory 3: Classes On Top of Classes
Due Date: Monday February 5, 2007.
In Chapter 3 you learned about the NumberDisplay and ClockDisplay classes. After gaining experience playing with these two classes, you are to build the AlarmClock class. It is strongly advised that you work through all the exercises in Chapter 3; especially those concerned with the clock classes and the use of a debugger.
The goal for this lab are to build more Java muscles: develop and build your own class on top of existing classes.
Alarm clocks keep track of two different times: the current time and the time the alarm is to ring.
The class AlarmClock will support the following methods:
- A constructor. Initialize both the current time and the alarm to midnight. The output style is initialized to the European output style.
- setAlarm and setClock: These methods allow for a user to input a new value for the alarm or the current time respectively. All input is assumed to be provided with integers in the 24 hour European style.
- setEuropeanDisplay and setAmericanDisplay: These methods toggle the state of the clock between displaying time values using the 24 hour European style and the 12 hour American style (with appropriate "a.m." and "p.m." suffixes added on).
- getAlarm and getClock: These two methods return to the caller the alarm time or the current time respectively as a String value. The output style is determined by which state the alarm clock is in: European or American.
- timeToAlarm: Return to the caller a String value indicating the number of hours and minutes between the current time and the alarm time.
You are to try and use the NumberDisplay and ClockDisplay classes unchanged.
You will need to know how to extract out substrings from a String value. One uses the substring method defined on String objects. This method takes two parameters, the starting position in the String value for the substring, and one plus the ending position in the String value for the substring. All position counting begins with zero.
For example: If the String object named instructor has been assigned the value "mikeyg" the expression
instructor.substring(0, 2) Þ "mi"
Finally, given a String value that represents an integer, to convert it into an Integer expression (instead of the String value) one uses the Integer.parseInt method on the String value to obtain its equivalent integer value.
File translated from
TEX
by
TTH,
version 3.74.
On 29 Jan 2007, 09:07.