java模拟电信月末计费的小程序(那位高手帮忙看看错在那里啊?)
程序要求如下:
编写一个线程,完成以下事情:每个月的最后一天下午5:30分做一件事情,(具体事情由自己确定),其中每
年的1、7、8月不做任何事情。
我写的程序代码如下:
import java.util.*;
public class XianCheng implements Runnable{
synchronized public void setTime(){
Calendar d= new GregorianCalendar(); //用类Calendar及其子类GregorianCalendar取得当前时间
int year = d.get(Calendar.YEAR);
int month = d.get(Calendar.MONTH)+1;
int day = d.get(Calendar.DAY_OF_MONTH);
int hour = d.get(Calendar.HOUR);
int minute = d.get(Calendar.MINUTE);
switch(month){
case 1:
case 7:
case 8: break;
case 4:
case 6:
case 9:
case 11:{
if (day==10&&hour==22&&minute==20)//在这里输入时间可用作测试...
System.out.println("终于等到这一刻了..呵呵...");
else
try{
wait();
}catch(InterruptedException e){}
}
break;
case 3:
case 5:
case 10:
case 12:{
if (day==31&&hour==17&&minute==30)
System.out.println("终于等到这一刻了..呵呵...");
else
try{
wait();
}catch(InterruptedException e){}
}
break;
case 2:{
while((year%4==0 && year%100!=0)|| year%400==0){
if(day==28&&hour==17&&minute==30)
System.out.println("终于等到这一刻了..呵呵...");
else
try{
wait();
}catch(InterruptedException e){}
}
if(day==29&&hour==17&&minute==30)
System.out.println("终于等到这一刻了..呵呵...");
else
try{
wait();
}catch(InterruptedException e){}
}
break;
}//出SWITCH
notifyAll();
}//出函数
public void run(){
while(true){//也不知死循环是不放在这里的..帮忙看看咯....
setTime();
}
}
public static void main(String []args){
System.out.println("系统开始运行.........");
System.out.println("");
System.out.println("本系统将在每个月最后一天17:30(1,7,8月份除外)打印'终于等到这一刻了..呵呵..':::");
XianCheng x=new XianCheng();
new Thread(x).start();
}
}
用当前时间作测试时什么反应也没有,可是程序也没有结束运行...无奈啊!!!!那位高手帮忙看看咯..