changing a 24 hour clock to a 12 hour clock

could somone please show me how to change this clock object to display 12 hour time instead of 24? using AM and PM as well? i've wrote this 24 hour clock from a walkthrough but cant figure out how to change it to a 12 hour clock? heres 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

*/

publicclass 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.

*/

publicvoid 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.

*/

publicvoid 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.

*/

privatevoid updateDisplay()

{

displayString = hours.getDisplayValue() +":" +

minutes.getDisplayValue();

}

}

[4171 byte] By [rich79a] at [2007-10-2 5:37:06]
# 1
> i've wrote this 24 hour clock Funny, it seems to me that Michael Kolling and David J. Barnes wrote it.
jfbrierea at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 2
will you be able to help me then?
rich79a at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 3
I don't understand what you need, but since you seem to be stealing code, I won't help you anyways...
Metallana at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 4
i havent stolen code mate.....just been given this to do by my uni!!!!so please dont bad mouth me!!!!.........if there is anyone out there that has any valid input it would be great to hear from you.....
rich79a at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 5
what is 1 pm on a 24 hr clock... 13...so 13 - 12 = 1...- MaxxDmg... - ' He who never sleeps... '
MaxxDmga at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 6
thanks he-who-never sleeps, but i know that part of it and i know that i have to put the code in the update display method...the problem comes when i want to do my if , else....im not really sure how to modify the way updateDisplay creates displayString?
rich79a at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 7

hi guys, I have come up with this formula but I am getting an error message.....operator >= cannot be applied to number dispaly int....please help!!!!!!

private void updateDisplay()

{

displayString = hours.getDisplayValue() + ":" +

minutes.getDisplayValue();

String Dn = "AM";

if ( hours >= 12)

{

Dn = "PM";

hours -= 12;

}

}

}

rich79a at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 8

Still getting the same error message; anyone got an idea of what is wrong?

private void updateDisplay()

{

displayString = hours.getDisplayValue() + ":" +

minutes.getDisplayValue();

if (hours >= 12)

{

hours = "PM";

hours -= 12;

}

else

{

hours = "AM";

}

}

}

rich79a at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 9
> Still getting the same error message; anyone got an> idea of what is wrong?You need to read the Java tutorial!
sabre150a at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 10
I have been looking at the tutorials cant seem to get this right so thats why i put the question on the forum mate!!!!.....help is in short supply, can anyone give me more than that?
rich79a at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...
# 11

> I have been looking at the tutorials cant seem to get this right so thats

> why i put the question on the forum mate!!!!.....help is in short supply,

> can anyone give me more than that?

I'm with Sabre here: you really should read some basic tutorials before

you attempt to write some Java code. The following statements:hours= "PM";

hours-= 12;

... don't make any sense at all. 'hours' is not a String type variable, so

you can't assign another String value to it. In the next line, you're attempting

to subtract the integer value 12 from it, which doesn't make any sense

either.

It doesn't help to just 'look at' the tutorials: you should read them thoroughly

and try to understand them. Nobody here is going to write the source

code for you; we all are willing to help when you get stuck on some

gory details, but what I can see now is that you don't even have a rudimentary,

basic understanding of the Java language. This forum is not a tutorial.

This is not intended to be an insult or an unwillingness to help. You

cannot be helped yet; please study the basics first.

kind regards,

Jos

JosAHa at 2007-7-16 1:47:36 > top of Java-index,Java Essentials,Java Programming...