import javax.swing.JOptionPane;
import java.text.DecimalFormat;

class Time1 ...{
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");
}
}

public class TimeTest3 ...{
public static void main(String args[]) ...{
Time1 time = new Time1();
time.setTime(0, 28, 56);
String output = "Universal time is :" + time.toUniversarString() + " Standard time is : " + time;
JOptionPane.showMessageDialog(null, output,
"Packaging class Time1 for Refuse ",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}

被折叠的 条评论
为什么被折叠?



