package 七周;
import javax.swing.JOptionPane;
public class time {
private int Hour ;
private int Minute ;
private int Second;
private void setHour(int newhour) {
if(newhour >= 0 && newhour <= 24) {
newhour = this.Hour;
}
else
this.Hour = 0;
}
private int getHour() {
return this.Hour;
}
private void setMinute(int newminute) {
if (newminute >= 0 && newminute <= 60) {
newminute = this.Minute;
}
else
this.Minute =0;
}
private int getMinute() {
return this.Minute;
}
private void setSecond(int newsecond) {
if (newsecond >= 0 && newsecond <= 60) {
newsecond = this.Second;
}
else
this.Second = 0;
}
private int getsecond() {
return this.Second;
}
private String toUniversalString() {
return this.Hour+":"+this.Minute+":"+this.Second;
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
time t = new time();
String output;
t.setHour(11);
t.setMinute(45);
t.setSecond(56);
output = t.toUniversalString();
JOptionPane.showMessageDialog(null, output);
}
}
你赋值写反了, this.Hour = newhour;
救救孩子吧