/**
* time1.java
* time1 class declaration maintains the time in 24-hour format.
*
* intan
*/
public class time1
{
private int hour; //0 - 23
private int minute; //0 - 59
private int second; //0 - 59
public void settime(int h, int m, int s)
{
if ((h >= 0 && h < 24) && (m >= 0 && m < 60) && (s >= 0 && s <60))
{
hour = h;
minute = m;
second = s;
} // end if
else
throw new IllegalArgumentException("Hour, minute and/or second was out of range");
} //end method settime
//convert to Sting in universal-time format (HH:MM:SS)
public String toUniversalString()
{
return String.format("%02d:%02d:%02d", hour, minute, second);
} //end method toUniversalString
//convert to Stirng in standard-time format (HH:MM:SS)
public String toString()
{
return String.format("%d:%02d:%02d %s",
((hour == 0 || hour == 12) ? 12 : hour % 12),
minute, second, ( hour < 12 ? "AM" : "PM"));
} //end method toString
} //end class time1