Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用for循环向队列添加不同的对象_Java_Queue - Fatal编程技术网

Java 如何使用for循环向队列添加不同的对象

Java 如何使用for循环向队列添加不同的对象,java,queue,Java,Queue,我想将CustomerQueue类型的10条记录添加到位于CustomerQueue本身内的CustomerQueue数组中,并打印出该数组。问题是它将“排队”保持在位置0,因为对于每个CustomerQueue对象,后面的值都重置为0。有什么解决办法吗 主要内容: 排队: public void enqueue(CustomerQueue cQ) { if (isFull()) { System.out.println("OverFlow\nProgram Termin

我想将CustomerQueue类型的10条记录添加到位于CustomerQueue本身内的CustomerQueue数组中,并打印出该数组。问题是它将“排队”保持在位置0,因为对于每个CustomerQueue对象,后面的值都重置为0。有什么解决办法吗

主要内容:

排队:

public void enqueue(CustomerQueue cQ) {
    if (isFull()) {
        System.out.println("OverFlow\nProgram Terminated");
        System.exit(1);
    }

    rear = (rear + 1);
    array[rear] = cQ;
    count++;
}
更改:

CustomerQueue cQ = null;
    for (int i = 0; i < 10; i++) {
        cQ = new CustomerQueue(1, 0, false);
        cQ.enqueue(cQ);
        System.out.println(cQ.arrivalTime);
    }
CustomerQueue cQ=null;
对于(int i=0;i<10;i++){
cQ=新CustomerQueue(1,0,false);
排队(cQ);
系统输出打印时间(cQ到达时间);
}

CustomerQueue cQ=null;
对于(int i=0;i<10;i++){
CustomerQueue子队列=新CustomerQueue(1,0,false);
排队(子队列);
System.out.println(子队列.到达时间);
}
如果您的要求不是这样,请发表评论

public void enqueue(CustomerQueue cQ) {
    if (isFull()) {
        System.out.println("OverFlow\nProgram Terminated");
        System.exit(1);
    }

    rear = (rear + 1);
    array[rear] = cQ;
    count++;
}
CustomerQueue cQ = null;
    for (int i = 0; i < 10; i++) {
        cQ = new CustomerQueue(1, 0, false);
        cQ.enqueue(cQ);
        System.out.println(cQ.arrivalTime);
    }
CustomerQueue cQ = null;
    for (int i = 0; i < 10; i++) {
        CustomerQueue subQueue = new CustomerQueue(1, 0, false);
        cQ.enqueue(subQueue);
        System.out.println(subQueue.arrivalTime);
    }