Making a 24 hour clock into a 12 hour clock, resetting to 1:00 not 00:00 without an if statement 0_o HELP?

Well we have this theoretical clock, It was 24 hours and we have to make it into a 12 hour clock for class. I figured out the am pm pretty easy with an if statement. However, our teacher said we would get no credit for the assignment if we used an if statement to make the clock reset to 1:00 and not 00:00. However... show more Well we have this theoretical clock, It was 24 hours and we have to make it into a 12 hour clock for class. I figured out the am pm pretty easy with an if statement. However, our teacher said we would get no credit for the assignment if we used an if statement to make the clock reset to 1:00 and not 00:00. However he said we could only put code in the timeTick method. I have looked at this for four hours, and come to the conclusion that, because you are only making the hours reset it has to be conditional. Therefore impossible without an if statement.

However, I believe that my teacher is not stupid and I am just missing something could anyone help???? Here is the code for the ClockDisplay method, and below that the numberdisplay method. No making two different numberdisplay methods and making the value in numberdisplay four hours did not work. It works when u first start the clock but not after that.

public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; // simulates the actual display
private String ampm = " am";


/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at 00:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(13);
minutes = new NumberDisplay(60);
hours.setValue(1);
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(13);
minutes = new NumberDisplay(60);
setTime(hour, minute);
hours.setValue(1);
}

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

if(hours.getValue() == 12 && minutes.getValue() <= 0 && ampm == " am")
{
ampm = " pm";
}

else
{
if(hours.getValue() == 12 && minutes.getValue() <= 0 && ampm == " pm")
{
ampm = " am";
}
}
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() + ampm;
}
}


public class NumberDisplay
{
private int limit;
private int value;

/**
* Constructor for objects of class NumberDisplay.
* Set the limit at which the display rolls over.
*/
public NumberDisplay(int rollOverLimit)
{
limit = rollOverLimit;
value = 0;
}

/**
* Return the current value.
*/
public int getValue()
{
return value;
}

/**
* Return the display value (that is, the current value as a two-digit
* String. If the value is less than ten, it will be padded with a leading
* zero).
*/
public String getDisplayValue()
{
if(value < 10) {
return "0" + value;
}
else {
return "" + value;
}
}

/**
* Set the value of the display to the new specified value. If the new
* value is less than zero or over the limit, do nothing.
*/
public void setValue(int replacementValue)
{
if((replacementValue >= 0) && (replacementValue < limit)) {
value = replacementValue;
}
}

/**
* Increment the display value by one, rolling over to zero if the
* limit is reached.
*/
public void increment()
{
value = (value + 1) % limit;
}
}
Update: Thank you a bunch for that help!!!! btw, i can use if statements for the ampm.

THANKS A TON AGAIN
2 answers 2