klllllll
klllllll

Reputation: 23

method for 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.

Upvotes: 2

Views: 235

Answers (1)

Sri
Sri

Reputation: 436

Good you are learning java and data structures..

This might work. please add elements to the Queue and try to display and

enter image description here

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] + "");
    }   
}

Upvotes: 3

Related Questions