我正在尝试使用计时器创建数组对象,每个客户必须用'cst'打印,所以我的问题是所有客户,包括构造函数中的1,同时打印,我的代码终止同样,最后我必须使用客户对象
class Customers extends TimerTask{
int cst;
Customers(int i) {
cst = i;
System.out.println("A Customer# "+cst+ " is added ");//should increment customer by one
}
@Override
public void run(){
//creating 10 objects of customers
Customers[] cstm = new Customers[10];
for(int count =0; count < cstm.length; count++){
cstm[count] = new Customers(count+1);
}
}
}
这是我在主要课程上的内容
public class MainClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Timer timer = new Timer();
timer.schedule(new Customers(1), 0,5000);
}
}