I have converted a 24 Hour Clock to the 12 hour clock. But for some reason when I put in 0:30 in it outputs it as 1:30am (Supposed to go to 12:30am) And when i put in 12:30 it goes to 1:30AM (Supposed to go to 12:30PM).
Can anyone help me with my problem?
Thanks!
/** * Write a description of class TwelveHourClock here. * * @author (your name) * @version (a version number or a date) */ public class TwelveHourClock { public NumberDisplay hours; public NumberDisplay minutes; public String displayString; private int timeZone = 1; public TwelveHourClock() { hours = new NumberDisplay(12); minutes = new NumberDisplay(60); setTime(12,0); } public TwelveHourClock(int hour, int minute){ hours = new NumberDisplay(12); minutes = new NumberDisplay(60); setTime(hour, minute); } private void updateDisplay(){ if(timeZone == 1){ displayString = getHourDisplay()+":"+minutes.getDisplayString() + " AM"; } else if(timeZone == 2){ displayString = getHourDisplay()+":"+minutes.getDisplayString() + " PM"; } } public String getHourDisplay(){ int value = hours.getValue()+1; if(String.valueOf(value).length() == 1){ return "0"+value; } return value+""; } public void timeTick(){ if(minutes.getValue() == 59){ hours.increment(); } minutes.increment(); updateDisplay(); } public void setTime(int hour, int minute){ hours.setValue(hour); minutes.setValue(minute); updateDisplay(); } public String getTime(){ return displayString; } }