英文:
method for display
问题
这是关于实现循环队列的内容,我会为你进行翻译。
package hotelbooking;
public class HotelBooking {
static int ROOM_CAPACITY = 33;
private static Customer[] waitingRoom = new Customer[ROOM_CAPACITY];
private static CustomerQueue hotelQueue = new CustomerQueue();
这是用于用户显示队列的方法。
private static void ViewhotelQueue() {
System.out.println("这是队列内容:");
hotelQueue.display();
}
package hotelbooking;
public class CustomerQueue {
private Customer[] queArray = new Customer[HotelBooking.ROOM_CAPACITY];
private int front = 0;
private int end = 0;
private int currentSize = 0; //当前循环队列的大小
public void display() {
//从front到end在queArray中列出元素
for (int i = front; i < currentSize; i++) {
System.out.println(queArray[(front+i)%queArray.length] + "");
queArray[i].display();
}
}
有人可以帮我吗?我遇到了很多困难。
英文:
I tried to implement a circular queue, where I would like to display my queue, however the only thing that gets displayed is "Here is my queue" and it just displays "null" rather then printing out the customer added to the queue. I cannot figure out why my queue will not be displayed. I am inserting a picture here to show what I am trying to say enter image description here.
My queue will consists of customers which are moved from the waitingRoom to CustomerQueue. The maximum amount of customers are 33.
Here is my code:
package hotelbooking;
public class HotelBooking {
static int ROOM_CAPACITY = 33;
private static Customer[] waitingRoom = new Customer[ROOM_CAPACITY];
private static CustomerQueue hotelQueue = new CustomerQueue();
This is the method for the user to display the queue.
private static void ViewhotelQueue() {
System.out.println("Here is the queue: ");
hotelQueue.display();
}
package hotelbooking;
public class CustomerQueue {
private Customer[] queArray = new Customer[HotelBooking.ROOM_CAPACITY];
private int front = 0;
private int end = 0;
private int currentSize = 0; //current circular queue size
public void display() {
//list elements from front to end in the queArray
for (int i = front; i < currentSize; i++) {
System.out.println(queArray[(front+i)%queArray.length] + "");
queArray[i].display();
}
}
Can someone please help me as I am struggling a lot.
答案1
得分: 3
好的,你正在学习Java和数据结构...
这可能有效。请向队列中添加元素,然后尝试显示
客户队列类中的一些更改
private int end = -1;
public void display() {
// 在队列数组中从前到后列出元素
for (int i = front; i < currentSize; i++) {
System.out.println(queArray[(front+i)%queArray.length] + "");
}
}
英文:
Good you are learning java and data structures..
This might work. please add elements to the Queue and try to display
and
Some changes in Customer Queue class
private int end = -1;
public void display() {
//list elements from front to end in the queArray
for (int i = front; i < currentSize; i++) {
System.out.println(queArray[(front+i)%queArray.length] + "");
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论