Question: / * * Constructor for ClockDisplay objects. This constructor * creates a new clock and set at 0 0 : 0 0 : 0 0

/** Constructor for ClockDisplay objects. This constructor
* creates a new clock and set at 00:00:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
seconds = new NumberDisplay(60); // create a new NumberDisplay for seconds with limit 60
updateDisplay();
}
/** Constructor for ClockDisplay objects. This constructor
* creates a new clock set at the time specified by the parameters.
* Add parameter for seconds
*/
public ClockDisplay(int hour, int minute, int second)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
seconds = new NumberDisplay(60);
setTime(hour, minute, second);
}
/** This method should get called once every second - it makes
* the clock display go one second forward
*/
public void timeTick()
{
seconds.increment(); // increment seconds
if(seconds.getVaue()==0)// seconds just rolled over?
{
minutes.increment(); // increment the minutes
if(minutes.getVaue()==0)// minutes just rolled over?
hours.increment(); // increment the hours
}
updateDisplay();
}
/** Set the time of the display to the specified hour, minute and second
* Add second parameter to the method
*/
public void setTime(int hour, int minute, int second)
{
hours.setValue(hour);
minutes.setValue(minute);
seconds.setValue(second);
updateDisplay();
}
/** Return the current time if this display in the format HH:MM:SS
*/
public String getTime()
{
return displayString;
}
/** Update the internal string that represents the display
* Add seconds display to include seconds in the time
*/
private void updateDisplay()
{
displayString = hours.getDisplayValue()+":"+ minutes.getDisplayValue()+":"
+ seconds.getDisplayValue();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!