// File: Clock24.java from the package edu.colorado.simulations
// Complete documentation is available from the Clock24 link in
// http://www.cs.colorado.edu/~main/docs/
package edu.colorado.simulations;
/******************************************************************************
* A Clock24
is a Clock
that provides its hour in
* 24-hour format (0 to 23) instead of 12-hour format. The purpose is to show
* how an extended class may override a method of the superclass.
*
* Java Source Code for this class:
*
* http://www.cs.colorado.edu/~main/edu/colorado/simulations/Clock24.java
*
*
* @author Michael Main
* (main@colorado.edu)
*
* @version Feb 10, 2016
*
* @see Clock
******************************************************************************/
public class Clock24 extends Clock
{
/**
* Get the current hour of this Clock24
, in 24-hour format.
* @return
* the current hour (always in the range 0...23)
**/
public int getHour( )
{
int ordinaryHour = super.getHour( );
if (isMorning( ))
{
if (ordinaryHour == 12)
return 0;
else
return ordinaryHour;
}
else
{
if (ordinaryHour == 12)
return 12;
else
return ordinaryHour + 12;
}
}
}