title: java - Queue method help needed
body: <p>I am doing a project in Java and I need to create a queue method.</p>
  
  <p>Every time someone is added to a room, they need to be added to the queue.</p>
  
  <p>I nee to create my own queue object in your program and write methods within the object to add to queue and take from queue. </p>
  
  <p>Every time a customer is added to a room it should use the
  queue object method to add the customer’s name to the queue. </p>
  
  <p>When the user selects to display the names of the last 3 customers the code should remove them from the queue one by one (first in first out) and display them as they are removed. </p>
  
  <p>The queue should be based on an array and hold 7 items.</p>
  
  <p>When the queue items reach the end of the array they should be added to the start or the array. </p>
  
  <p>If the queue becomes full then an error message should be displayed and the oldest queue item should be <strong>automatically</strong> removed and displayed.</p>
  
  <p>This is the main body: </p>
  
  <pre><code>package hotelcoursework2;
  
  import java.util.*;
  
  public class HotelCourseWork2 {
  
      public static void main(String[] args) {
  
          Room[] myHotel = new Room[10];
          Queue mq = new Queue();
  
          int guests = 0;    
          String roomName = null;
          int roomNum = 0;
          String letter = "";
  
          for (int i = 0; i &lt; myHotel.length; i++) {
              myHotel[i] = new Room();
  
          }
  
          do {
              System.out.println("Press E to display empty rooms");
              System.out.println("Press A to add customers to room");
              System.out.println("Press V to view all rooms ");                  
              System.out.println("Press D to delete customers from rooms");
              System.out.println("Or enter 1 to add to queue, 2 to take from queue or 3 display queue");
              System.out.println("Press S to save");
              System.out.println("Press L to load");
              System.out.println("Press X to exit");
              System.out.println("Enter a Letter: ");
              Scanner scan = new Scanner(System.in);
              letter = scan.next();
  
              if (letter.equals("A")) {
                  add(myHotel, roomNum, roomName, guests);
  
                  mq.addqueue();
              }
              if (letter.equals("V")) {
                  view(myHotel);
              }      
              if (letter.equals("E")){
                  empty(myHotel);
              }
  
              if(letter.equals("D")){
                  delete(myHotel, roomNum);
                  mq.takequeue();
             }
  
              if (letter.equals("S")){
  
              }    
  
              if(letter.equals("3")){
                  mq.displayqueue();
              }
  
  
          } while (letter.charAt(0) != 'X');
          System.out.println("Exit successfull");
  
      }
  
  
     private static void add(Room myHotel[], int roomNum, String roomName, int guests) {
          Scanner input = new Scanner(System.in);
          System.out.println("Enter room number (0-9) or 10 to stop:");
          roomNum = input.nextInt();
          if (roomNum == 10) {
              System.out.println("Exit successful");
              System.exit(0);
          }
          System.out.println("Enter name for room " + roomNum + " :");
          roomName = input.next();
          myHotel[roomNum].setName(roomName);
          System.out.println("Enter how many guests: ");
          guests = input.nextInt();
          myHotel[roomNum].setGuestsInRoom(guests);
          System.out.println("Add customers to queue: ");
  
  
          for (int i = 0; i &lt; 10; i++) {
              System.out.println("Customer " + myHotel[i].getName() + " has been allocated to room " + i
               + " with " + myHotel[i].getGuestsInRoom() + " guests. ");
  
          }
      }
  
     private static void view(Room myHotel[]) {
  
          for (int i = 0; i &lt; 10; i++) {
              System.out.println("room " + i + " occupied by " + myHotel[i].getName() );
          }
      }
  
     private static void empty(Room myHotel[]) {
          for (int i = 0; i &lt; 10; i++) {
              if (myHotel[i].getName().equals("no-one")) {
                  System.out.println("room " + i + " is empty");
              }
          }
      }
  
     private static void delete(Room myHotel[], int roomNum){
          Scanner input = new Scanner(System.in);
          System.out.println("Enter room number you want to delete a customer from: ");
          roomNum = input.nextInt();
          myHotel[roomNum].setName("no-one");
  
     }
  
  
  
  }
  </code></pre>
  
  <p>This is the class I have created for the queue but now I am stuck.The queue should be first in first out. </p>
  
  <pre><code>package hotelcoursework2;
  import java.util.Scanner;
  
  public class Queue {
  
      // be careful - this queue can go over the end of the array
      //the array should be used in a circular way
      private static String qitems[] = new String[7];
      private static int front = 0, end = 0;
  
      static void addqueue() {
          Scanner input = new Scanner(System.in);
          System.out.print("Enter someone to the queue :");
          qitems[end] = input.next();
          end++;
  
      }
  
      static void takequeue() {
          if (end &gt; front) {
              System.out.println("Person remove :" + qitems[front]);
              front++;
          } else {
              System.out.println("Empty queue");
          }
      }
  
      static void displayqueue() {
          System.out.println("Queue display: ");
          for (int look = front; look &lt; end; look++) {
              System.out.print(" " + qitems[look]);
          }
          System.out.println("");
      }
  </code></pre>
  
  <p>}</p>