24 hour clock to 12 hour clock project.
Hi guys, i am working through a java book and have come across this challenge exercise where we are told to create a 24 hour clock which i have accomplished.
They now have told us to change the 24 hour clock into a 12 hour clock which i have 90% completed but am having a problem with the am/pm string that is shown at the end of the clock display.
Currently i have used if statements to do the following,
public void timeTick()
{
minutes.increment();
if(minutes.getValue() == 0) { // it just rolled over!
hours = hours + 1;
}
if(hours > 12)
{
hours = hours -12;
}
updateDisplay();
}
This gets the value if its 13+ and subtracts 12 to get the 12hour clock result.
The problem i am having is the following to display the am/pm
I created the following method,
private String updateDisplayTwo()
{
if(hours > 12)
{
amPm = "pm";
}
else
{
amPm = "am";
}
return amPm;
}
Now i know where the problem lies as the hours data is never going to be 13+ anymore because if it is then 12 is subtracted from it.
What i was wondering is there anything within java that will 'show' when a method had been used and been activated. As i belive if i can tell when the 12> function is being used i can use that in another IF statement to show the pm string instead of the constant am (currently).
Thanks in advance guys.
Re: 24 hour clock to 12 hour clock project.
Hi, i am doing the same assignment for my uni this year please can i ask you for a help if you have done this assignment already can i get the proper code as i am stuck in various places please if you can mail me the actual coding on my email address which is [email address removed] i'll really appreciate that
my assignment is due tomorrow please try an reply me back ASAP!
Re: 24 hour clock to 12 hour clock project.
Don't resurrect a very old thread; start your own thread and don't beg for code; that's cheating.
kind regards,
Jos
ps. I'm closing this threaad.