2

When I run my program the hour does not restart back to zero instead it keeps going.

For example if Tower A is at 0 and Tower B is at 23 and I want to add 8 hours

My code outputs:
Tower A is at 9 and Tower B is at 32.

public void advanceClock(int numHours)

{

    if (hour >= 0 && hour <= 23)

    {
    hour = hour + numHours;
    advanceOneHour();
    }   
}

This is what the instance method should do:

public void advanceClock (int numHours)

Advances the current hour on this ClockTower by numHours hours. The hour will always be between 0 (midnight) and 23 (i.e., the next hour after 23 is 0).

Expected output is:
Tower A is at 8 and Tower B is at 7.

smilyface
  • 5,021
  • 8
  • 41
  • 57

0 Answers0