?? time2.java
字號:
// Time2.java類的定義
public class Time2 {
private int hour; // 0 - 23
private int minute; // 0 - 59
private int second; // 0 - 59
// Time2 constructor initializes each instance variable
// to zero. Ensures that Time object starts in a
// consistent state.
public Time2()
{
setTime( 0, 0, 0 );
}
// Time2 constructor: hour supplied, minute and second
// defaulted to 0
public Time2( int h )
{
setTime( h, 0, 0 );
}
// Time2 constructor: hour and minute supplied, second
// defaulted to 0
public Time2( int h, int m )
{
setTime( h, m, 0 );
}
public Time2( int h, int m, int s )
{
setTime( h, m, s );
}
// Time2 constructor: another Time2 object supplied
public Time2( Time2 time )
{
setTime( time.hour, time.minute, time.second );
}
// Set a new time value using universal time. Perform
// validity checks on data. Set invalid values to zero.
public void setTime( int h, int m, int s )
{
hour = ( ( h >= 0 && h < 24 ) ? h : 0 );
minute = ( ( m >= 0 && m < 60 ) ? m : 0 );
second = ( ( s >= 0 && s < 60 ) ? s : 0 );
}
// convert to String in universal-time format
public String toUniversalString()
{
return hour + ":" + minute + ":" + second ;
}
// convert to String in standard-time format
public String toString()
{
return ((hour == 12 || hour == 0) ? 12 : hour % 12 ) +":" + minute+":" + second + ( hour < 12 ? " AM" : " PM" );
}
public static void main( String args[] )
{
Time2 t1, t2, t3, t4, t5, t6;
t1 = new Time2(); // 00:00:00
t2 = new Time2( 2 ); // 02:00:00
t3 = new Time2( 21, 34 ); // 21:34:00
t4 = new Time2( 12, 25, 42 ); // 12:25:42
t5 = new Time2( 27, 74, 99 ); // 00:00:00
t6 = new Time2( t4 ); // 12:25:42
System.out.println(t1.toUniversalString()+'\t'+ t1.toString());
System.out.println(t2.toUniversalString()+'\t'+ t2.toString());
System.out.println(t3.toUniversalString()+'\t'+ t3.toString());
System.out.println(t4.toUniversalString()+'\t'+ t4.toString());
System.out.println(t5.toUniversalString()+'\t'+ t5.toString());
System.out.println(t6.toUniversalString()+'\t'+ t6.toString());
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -