-
October 22nd, 2011, 12:41 AM
#1
JAVA 1 Class, NEED HELP
I am looking for advise the answer.
I am in a JAVA 1 programing class online and right now we are working on a 24 to 12 hour clock conversion. We are only able to change the timeTick method, the constructors and the setTime
Here is where I am at
[code]
/**
* The ClockDisplay class implements a digital clock display for a
* 12 hour clock. The clock shows hours and minutes. The
* range of the clock is 12:00am (midnight) to 11:59pm (one minute before
* midnight).
*
* The clock display receives "ticks" (via the timeTick method) every minute
* and reacts by incrementing the display. This is done in the usual clock
* fashion: the hour increments when the minutes roll over to zero.
*
* @author Michael Kolling and David J. Barnes
* @version 2008.03.30
*
* Tyler Hord
* Modafications:
*/
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 12:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(12);
minutes = new NumberDisplay(60);
updateDisplay();
}
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at the time specified by the
* parameters.
*/
public ClockDisplay(int hour, int minute)
{
hours = new NumberDisplay(12);
minutes = new NumberDisplay(60);
setTime(hour, minute);
}
/**
* This method should get called once every minute - it makes
* the clock display go one minute forward.
*/
public void timeTick()
{
minutes.increment();
if(minutes.getValue() == 0) { // it just rolled over!
hours.increment();
}
updateDisplay();
if(updateDisplay() == "00:00"){
return "12:00";}
}
/**
* Set the time of the display to the specified hour and
* minute.
*/
public void setTime(int hour, int minute)
{
hours.setValue(hour);
minutes.setValue(minute);
updateDisplay();
}
/**
* Return the current time of this display in the format HH:MM.
*/
public String getTime()
{
return displayString;
}
/**
* Update the internal string that represents the display.
*/
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue();
}
}
[code]
Please help. Advise or ideas only please no answers.
-
October 22nd, 2011, 05:59 AM
#2
Re: JAVA 1 Class, NEED HELP
Duplicate post. See this thread
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|