/**
* set time, and convert time to string with formats
*
* @author Steve Daniels
* @version 1.0.1
*/
public class Time1
{
private int hour;
private int minute;
private int second;
//
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 setTime
//convert to String in format HH:MM:SS
public String toUniversalString()
{
return String.format( "%02d:%02d:%02d", hour, minute, second );
} // end toUniversalString
//convert to string i format H:MM:SS AM/PM
public String toString()
{
return String.format( "%d:%02d:%02d %s",
( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ),
minute, second, ( hour < 12 ? "AM" : "PM" ) );
}
}