All it is, is a simple program that asks to enter hour and minute and makes the clock tick, after ticking, when clock is viewed, it should read a minute ahead. Very proud of the results. The only issue is getting PM to fire when time ticks beyond 24 hours. Just a matter of time, but do tell me what you see happening, I am sure it is pretty simple...
[CODE=JAVA]
/**
* @author Michael Kölling and David J. Barnes
* @version 2007.10.03
* @professor The Nice One
* @programmer Just Me
* @Lab 5
*/
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; // simulates the actual display
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at 00:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(1 2);
minutes = new NumberDisplay(5 9);
updateDisplay() ;
}
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at the time specified by the
* parameters.
*/
public ClockDisplay(in t hour, int minute)
{
hours = new NumberDisplay(1 2);
minutes = new NumberDisplay(5 9);
setTime(hour, minute);
}
/**
* This method should get called once every minute - it makes
* the clock display go one minute forward.
*/
public void timeTick()
{
minutes.increme nt();
if(minutes.getV alue() == 0) { // it just rolled over!
hours.increment ();
}
updateDisplay() ;
}
/**
* Set the time of the display to the specified hour and
* minute.
*/
public void setTime(int hour, int minute)
{
hours.setValue( hour);
minutes.setValu e(minute);
updateDisplay() ;
}
/**
* Return the current time...
*/
public String getTime()
{
return displayString;
}
/**
* Update the internal string that represents the display.
*/
private String updateDisplay()
{
if(hours.getVal ue() < 12){
return displayString = hours.getValue( ) + ": " +
minutes.getValu e() + " AM";
}
else {
return displayString = hours.getValue( ) + ": " +
minutes.getValu e() + " PM";
}
}
}
[/CODE]
Thanks for reading!
[CODE=JAVA]
/**
* @author Michael Kölling and David J. Barnes
* @version 2007.10.03
* @professor The Nice One
* @programmer Just Me
* @Lab 5
*/
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; // simulates the actual display
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at 00:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(1 2);
minutes = new NumberDisplay(5 9);
updateDisplay() ;
}
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at the time specified by the
* parameters.
*/
public ClockDisplay(in t hour, int minute)
{
hours = new NumberDisplay(1 2);
minutes = new NumberDisplay(5 9);
setTime(hour, minute);
}
/**
* This method should get called once every minute - it makes
* the clock display go one minute forward.
*/
public void timeTick()
{
minutes.increme nt();
if(minutes.getV alue() == 0) { // it just rolled over!
hours.increment ();
}
updateDisplay() ;
}
/**
* Set the time of the display to the specified hour and
* minute.
*/
public void setTime(int hour, int minute)
{
hours.setValue( hour);
minutes.setValu e(minute);
updateDisplay() ;
}
/**
* Return the current time...
*/
public String getTime()
{
return displayString;
}
/**
* Update the internal string that represents the display.
*/
private String updateDisplay()
{
if(hours.getVal ue() < 12){
return displayString = hours.getValue( ) + ": " +
minutes.getValu e() + " AM";
}
else {
return displayString = hours.getValue( ) + ": " +
minutes.getValu e() + " PM";
}
}
}
[/CODE]
Thanks for reading!
Comment