程序代码如下,还是一本书上的例题,真是让人不可思议,不知道问题倒底出在什么地方
package c.czg;
import java.text.DecimalFormat;
public class Time3 extends Object {
private int hour ;
private int minute ;
private int second ;
public Time3 ()
{
setTime ( 0,0,0 );
}
public Time3 ( int h )
{
setTime ( h,0,0 );
}
public Time3 ( int h, int m )
{
setTime ( h,m,0 );
}
public Time3 ( int h,int m,int s )
{
setTime ( h,m,s );
}
public Time3 ( Time3 time )
{
setTime ( time.getHour(),time.getMinute(),time.getSecond() );
}
public void Time3 ( int h,int m,int s )
{
setHour ( h );
setMinute ( m );
setSecond ( s );
}
public void setHour ( int h )
{
hour = ( ( h>=0 && h<24 ) ? h:0 );
}
public void setMinute ( int m )
{
minute = ( ( m>=0 && m<60 ) ? m:0 );
}
public void setSecond ( int s )
{
second = ( ( s>=0 && s<60 ) ? s:0 );
}
public int getHour ()
{
return hour ;
}
public int getMinute ()
{
return minute ;
}
public int getSecond ()
{
return second ;
}
public String toUniversalString ()
{
DecimalFormat two = new DecimalFormat ("00");
return two.format ( getHour() ) + ":" +
two.format ( getMinute() ) + ":" +
two.format ( getSecond() );
}
public String toString()
{
DecimalFormat two = new DecimalFormat ("00");
return ( ( getHour() ==12 || getHour() == 0 ) ?
12: getHour() %12 ) + ":" +
two.format ( getMinute() ) +
two.format ( getSecond() ) +
( getHour()<12 ? "AM" : "PM" );
}
}
----------------解决方案--------------------------------------------------------