小弟不知道如何进行编译和执行,尝试一天也没有结果请大家帮忙,十二分感谢!
安装目录如下:C:\Program Files\Java\jdk1.6.0
环境变量配置如下:PATH=C:\Program Files\Java\jdk1.6.0\bin; C:\Windows;C:\Windows\Command
classpath=. ;C:\Program Files\Java\jdk1.6.0\lib\tools.jar
源文件保存在:E:\java
程序源代码如下:
package com.deitel.jhtp4.ch08;
import java.text.DecimalFormat;
public class Time1 extends Object
{
private int hour;
private int minute;
private int second;
public Time1 ( )
{ setTime ( 0 ,0 , 0 );
}
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 );
}
public String toUniversarString ( )
{
DecimalFormat twoDigits = new DecimalFormat ( "00" );
return twoDigits.format ( hour ) + ":" + twoDigits.format ( minute ) + ":" + twoDigits.format ( second );
}
public String toString ( )
{
DecimalFormat twoDigits = new DecimalFormat ( "00" );
return (( hour ==12 || hour == 0 ) ? 12 : hour % 12 ) +
":" + twoDigits.format ( minute ) + ":" + twoDigits.format ( second ) +
( hour < 12 ? "AM" : "PM" );
}
}
import javax.swing.JOptionPane;
import com.deitel.jhtp4.ch08.Time1;
public class TimeTest3
{
public static void main ( String args[] )
{
Time1 time = new Time1 ( );
time.setTime ( 17, 27, 06 );
String output = "Universal time is :" + time.toUniversalTime ( ) + "\n Standard time is : "+ time.toSting ( );
JOptionPane.showMessageDialog ( null, output, "Packaging class Time1 for Refuse ",JOptionPane.INFORMATION_MESSAGE );
System.exit ( 0 );
}
}