An aircraft has 200 seats each row has 4 seats with an isle

An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two seats on the right side of the airplane. There are 50 rows Seat reservation is problematic because multiple users attempt to reserve seats at the same time and they are not aware of one another. Obvious conflicts can occur, for example, two users attempting to reserve the same seat at the same time. For this question you will implement three threads that will attempt seat reservations. These threads will represent brokers who provide this service to customers. Two threads will be automated producer functions that randomly attempt seat reservations. The third producer will not be automated; instead it is a GUI Swing form that you will use to make manual reservations, as the third broker. Each producer has an ID number: 1, 2, and 3. These ID numbers will be recorded with the seat reservation so that we can know which producer did what. The GUI displays the airplane seats together with the producer ID number and if the seat is available. To do this you have two choices: choice 1- draw a white box for each seat. An empty white box means the seat is available. A successfully reserved seat will have the producer\'s ID number written within the box. Choice 2- print a string of underline characters (IE. _for each empty seat. Overwrite the underline with the producers ID number to indicate that it is taken (in other words, not a graphic based solution). Use the row and column number method to identify which seat you are interested in. To summarize, this swing GUI displays the reservation form and the airplane seating availability diagram

Solution

import java.util.Scanner;

// Need for the Scanner class.

public class Seating

{

    // Fields.

    // Create an 2D array that has 15 rows and 6 colums.

    private char[][] seats;

    private static String lastName; // To hold the last Name.

    private static final char EMPTY_SEAT = \'X\';

    private static final char FILLED_SEAT = \'O\';

    

    // Create a instance of the CustomerName class.

    CustomerName ln = new CustomerName(lastName);

    

    // Create a instance of the TicketType class.

    //TicketType tty = new TicketType(FirstClass, EconomyClass);

    //The displaySeats method shows the seats to the user.

    public static void displaySeats ( char [][] seats )

    {

        // Populate the 2-dimensional array

          /* for ( int r = 0; r < seats.length; r++ )

           {

               for ( int c = 0; c < seats[r].length ; c++ )

               {

                   seats [r] [c] = EMPTY_SEAT;

               } // End of inner for loop

     } // End of outer for loop

*/

            //This nested for loop displays the seats on the airplane.

       System.out.println ( \"                S E A T S\ \" );

            System.out.println(\"\\t           A   B   C   D   E   F \ \");

            

           for ( int r = 0; r < seats.length; r++ )

            {

                 if ( (r+1) < 10 )

                  System.out.print ( \"Row Number:   \"+ (r+1) + \"    \" );

                else

                  System.out.print ( \"Row Number: \"+ (r+1) + \"    \" );

                

               for ( int c = 0; c < seats[r].length; c++ )

               {

                  System.out.print ( seats[r] [c] + \"   \" );

               } // End of inner for loop

                  System.out.println ();

                  

            } // End of outer for loop

            System.out.print(\"\ \");

            System.out.println(\"Rows 1,2 and 3 are first class; \" +

                               \" the remaining rows are economy class.\");

           

            System.out.print(\"Rows 1 through 9 are interent ready.\ \");

            System.out.print(\"\ \");

        } // End of the displaySeats method.

        /*

     The displayMenu method shows the opinions that a user can chose

     from.

    */

    

    public static void displayMenu()

    {

      System.out.println ( \"Choose one of the following opinions:\" );

      System.out.println ( \"1   Book a seat\" );

      System.out.println ( \"2   Cancel a booking\" );

      System.out.println ( \"3   Write human-readable output file\" );

      System.out.println ( \"4   Write machine-readable output file\" );

      System.out.println ( \"5   Exit program\ \" );

      System.out.println ();

    } // End of the displayMenu method

    //=============================================

    // The getMenuResponse method returns what the user chose.

    

    public static char getMenuResponse ()

   {

      // Create a Scanner object for keyboard input.

      Scanner keyboard = new Scanner(System.in);

      // Get the user\'s response to the menu

      System.out.print ( \"Enter your choice:   \" );

      String s = keyboard.next();

      char choice = s.charAt(0);

      return choice;

   } // End of the getMenuResponse method.

   //===============================================

   

   // The MenuResponse method takes what user choose.

   public static void MenuResponse ( char response, char [][] seats ) //throws IOException

   {  

       // Create a Scanner object for keyboard input.

      Scanner keyboard = new Scanner(System.in);

      

      switch (response)

      {

         case \'1\':

            System.out.println(\"You want to book a seat.\");

            // Ask the user to enter his/her last name.

            System.out.println(\"Pleae enter your last name\");

            lastName = keyboard.nextLine();

                         

            System.out.print(\"\ \");

        

            break;

         case \'2\':

            System.out.println(\"You want to cancel a booking.\");

            keyboard.nextLine();

            break;

         case \'3\':

            System.out.println(\"You want to write a human-readable file.\");

            break;

         case \'4\':

            System.out.println(\"You want to write a machine-readable file.\");

            break;

         case \'5\':

            System.out.println(\"Exit program.\");

            System.exit ( 1 );

            break;

         default:

        System.out.println(\"Not an acceptable response !!!\");

      }

   } // End of the MenuResponse method.

   //====================================================

   

   /*

     The displayTicketMenu method shows the opinions that a user

     can choose from.

    */

//========================================================

    

    public static void displayTicketMenu()

    {

      System.out.println ( \"Choose one of the following tickets:\" );

      System.out.println ( \"1. First class\" );

      System.out.println ( \"2. Economy class\" );

      System.out.println ( \"3. Exit program\ \" );

      System.out.println ();

    } // End of the displayMenu method.

    //================================================

    // The getTicketResponse method returns what the user choose.

    

    public static char getTicketResponse ()

   {

      // Create a Scanner object for keyboard input.

      Scanner keyboard = new Scanner(System.in);

      // Get the user\'s response to the menu

      System.out.print ( \"Enter your choice:   \" );

      String s = keyboard.next();

      char choice = s.charAt(0);

      return choice;

   } // End of the getTicketResponse method.

   //=======================================================

    

   // The ticketResponse method takes what user choose and excutes it.

    public static void ticketResponse(char ticketType, char[][] seats)

    {

        String input; // To hold the input.

        char choice; // To store the user\'s choice

        // Create a Scanner object for keyboard input.

        Scanner keyboard = new Scanner(System.in);

        

        switch (ticketType)

        {

      case \'1\' :

            System.out.println(\"You want a ticket in first class\");

                if (ticketType == 1)

                {

                    System.out.println(lastName);

                }

            

        break;

        case \'2\':

            System.out.println(\"You want a ticket in second class\");

       System.out.println();

            System.out.println(\"What section do you want to seat in\" +

                               \" 1. Interent\" +

                               \" 2. No-Interent\");

            input = keyboard.nextLine();

           choice = input.charAt(0); // Get the first char.

            // Get what user choose and excute it.

            switch (choice)

            {

            case \'1\':

                System.out.println(\"Interent section\");

                break;

            case \'2\':

                System.out.println(\"No-Interent section\");

                break;

            default:

                System.out.println(\"Not an acceptable response !!!\");

           

            }

            

             

        break;

        case \'3\':

            System.out.println(\"Exit program\ \");

            System.exit ( 1 );

        

        default:

            System.out.println(\"Not an acceptable response !!!\");

        

        } // End of the switch.

    } // End of the ticketResponse method.

    //======================================================

    

    // The isFirstClassfull method check to see if there is a empty seat.

        public static boolean isFirstClassfull(char[][] seats)

        {

            boolean answer = true; // Flag.

            for (int row = 0; row < 3; row++ )

            {

                for (int col = 0; col < seats[0].length; col++ )

                   if (seats[row][col] == EMPTY_SEAT)

                         answer = false;

            }

            return answer;

        }

}

 An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two sea
 An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two sea
 An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two sea
 An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two sea
 An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two sea
 An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two sea
 An aircraft has 200 seats; each row has 4 seats with an isle in the middle. In other words, two seats on the left side of the airplane a space and then two sea

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site