Section 11 -- April 10-11
This is an optional exercise. Work on this exercise only if you have done most of Project 5.
Implement the functionality of a radio alarm clock. Write a class RadioAlarmClock that implements an alarm clock with 2 bandwidth radio and a buzzer option alarm. The two bandwidth should not overlap.
The class should have the following fields:
- private boolean radioOn - if true the radio is playing the station;
- private boolean alarmOn - if true the alarm will go off at alarm time;
- private boolean buzzerOn - sets the buzzer alarm on instead of the radio alarm;
- private double startBandWidth1 - the start of the first bandwidth;
- private double endBandWidth1 - the end of the first bandwidth;
- private double startBandWidth2 - the start of the second bandwidth;
- private double endBandWidth2 - the end of the second bandwidth;
- private int bandwidth - has values 1 or 2 depending on the selected bandwidth;
- private double station1 - the frequency of the current station in first bandwidth;
- private double station2 - the frequency of the current station in second bandwidth;
- private int startHour - hour of the base time;
- private int startMin - minute of the base time;
- private int startSec - second of the base time;
- private int alarmHour - hour of the alarm time;
- private int alarmMin - minute of the alarm time;
- private int alarmSec - second of the alarm time;
You should implement the following constructors and methods:
- RadioAlarmClock(double startBandWidth1, double endBandWidth1,
double startBandWidth2, double endBandWidth2) - initializes the radio at midnight;
- RadioAlarmClock(double startBandWidth1, double endBandWidth1,
double startBandWidth2, double endBandWidth2,
int hour, int minute, int second) - uses a preset time to initialize the clock;
- public void switchRadioOnOff() - turns the radio on/off;
- public void switchAlarmOnOff() - set the alarm on and it turns it off;
- public void switchBuzzerOnOff() - switches between alarm modes - buzzer/radio;
- public void setTime(int hour, int minute, int second) - set the start time;
- public String getTime() - returns a representation of the current time using the time elapsed from last setting of the start time;
- public void setAlarmTime(int hour, int minute, int second) - sets the alarm time;
- public void chooseBandwidth(int bandwidth) - chooses between the bandWidth;
- public void tuneRadio(double frequency) - selects the radio station in the current bandwidth;
- public String toString() - returns a representation of the current state of the radio;
To get the system time assume that the existence of two methods that can be easily implemented using class Date from package java.util:
- private void setTimeStamp() - this method sets time stamp that
- private long getTimeElapsed() - this methods returns the time in milliseconds that elapsed from the time stamp previously set
The RadioAlarmClock has two constructors one that initializes the radio at midnight and one that uses a preset time to initialize the clock. The bandwidths should be initialized in the constructor and cannot be changed later. The "getTime" function should return human readable string representing the current time of the clock. (Hint: to measure it get the time elapsed from the time you last set the time). Also be careful that the time wraps at midnight, assume the 24 hour representation. The format of the string is "hh:mm:ss".
To keep things simple the bandwidth don't have to be real bandwidth but intervals on the real line and you don't have to implement the "wake up function".