aspose file tools*
The moose likes Beginning Java and the fly likes Please help me this. Im new to this. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help me this. Im new to this." Watch "Please help me this. Im new to this." New topic
Author

Please help me this. Im new to this.

Alex B Smith
Greenhorn

Joined: Apr 12, 2006
Posts: 2
hey

Im doing a coursework using BlueJ and i need help on the coding for a clock-display project. I have to change a clock from 24-hour clock to a 12-hour clock display. Im from england by the way.

thanks
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
post your code that displays the 24 hour clock
Alex B Smith
Greenhorn

Joined: Apr 12, 2006
Posts: 2
hey
here is the code:
/**
* The ClockDisplay class implements a digital clock display for a
* European-style 24 hour clock. The clock shows hours and minutes. The
* range of the clock is 00:00 (midnight) to 23:59 (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 2001.05.26
*/
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(24);
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(24);
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();
}

/**
* 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();
}
}

hope this helps! I have the other 2 files if u want them! I appreciate this!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Hmmm... I'm guessing the code for NumberDisplay looks something like what's below. But the assignment also says something like, "DO NOT change the NumberDisplay. Hint: maintain the 24-hour clock behind the scenes, and merely change how it displays the time."

Right?

[ April 12, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Please help me this. Im new to this.