Clock类的代码:
public class Clock {
Display hour=new Display(24);
Display minute=new Display(60);
Display second=new Display(60);
public Clock(int a, int b, int c){
hour.setvalue(a);
minute.setvalue(b);
second.setvalue(c);
}
public void tick(){
second.increase();
if(second.getvalue()==0){
minute.increase();
if(minute.getvalue()==0){
hour.increase();
}
}
}
public String toString(){
return String.format("%02d:%02d:%02d\n",hour.getvalue(),minute.getvalue(),second.getvalue());
}
Display类部分的代码:
public class Display {
private int value=0;
private int limit=0;
public Display(int limit){
this.limit=limit;
}
public void setvalue(int value){
this.value=value;
}
public void increase(){
value++;
if(value==limit){
value=0;
}
}
public int getvalue(){
return value;
}String.format("%02d:%02d:%02d\n",hour.getvalue(),minute.getvalue(),second.getvalue());
}
网友评论