方法用于显示

huangapple go评论88阅读模式
英文:

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(&quot;Here is the queue: &quot;);
        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 &lt; currentSize; i++) {
            System.out.println(queArray[(front+i)%queArray.length] + &quot;&quot;);
            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 &lt; currentSize; i++) {
        System.out.println(queArray[(front+i)%queArray.length] + &quot;&quot;);
    }   
}

huangapple
  • 本文由 发表于 2020年4月11日 13:15:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/61152421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定