优质解答
class Clock{
private int hourse;
private int minute;
private int second;
public Clock(){
this.hourse=0;
this.minute=0;
this.second=0;
}
public void incSecond(){
this.second+=1;
}
public void toTime(){
if(this.hourse>24){this.hourse=0;}
if(this.minute>60){this.hourse+=1;this.minute-=60;}
if(this.second>60){this.minute+=1;this.second-=60;}
System.out.printf(hourse+":"+minute+":"+second);
}
public void setHourse(int hourse) {
this.hourse = hourse;
}
public void setMinute(int minute) {
this.minute = minute;
}
public void setSecond(int second) {
this.second = second;
}
}
public class test {
public static void main(String[] args) {
Clock c=new Clock();
c.setMinute(66);//测试数据
c.setSecond(61);
c.toTime();//输出1:7:1
}
}
基本功能实现.没有添加访问器.但有些代码可以修改的更好,可以的话给分我吧.