clock:
package wannianli;
public class Clock {
private Display hour = new Display(24);
private Display miniute= new Display(60);
private Display second= new Display(60);
private Display year= new Display(9999);
private Display month= new Display(12);
private Display day;
public void start()
{
int i,j;
for(; ; )
{
i=year.getValue();
j=month.getValue();
if(i%4000||i%40&&i%100!=0)
{
if(j2)
{
day=new Display(29);
}
else if(j1||j3||j5||j7||j8||j10||j12)
{
day=new Display(31);
}
else
{
day=new Display(30);
}
}
else
{
if(j2)
{
day=new Display(28);
}
else if(j1||j3||j5||j7||j8||j10||j12)
{
day=new Display(31);
}
else
{
day=new Display(30);
}
}
second.increase();
if (second.getValue() == 0)
{
miniute.increase();
if (miniute.getValue() == 0)
{
hour.increase();
if(hour.getValue() == 0)
{
day.increase();
if(day.getValue() == 0)
{
month.increase();
if(month.getValue() == 0)
{
year.increase();
}
}
}
}
}
System.out.printf("%04d:%02d:%02d:%02d:%02d:%02d\n", year.getValue(),month.getValue(),day.getValue(),hour.getValue(), miniute.getValue(),second.getValue());
}
}
public static void main(String[] args) {
Clock c = new Clock();
c.start();
}
}
display
package wannianli;
public class Display {
private int value=0;
private int limit=0;
public Display(int limit)
{
this.limit = limit;
}
public void increase()
{
value++;
if (value == limit)
{
value = 0;
}
}
public int getValue()
{
return value;
}
}