Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A small airline company has just purchased a computer for itsnew automated reser

ID: 3614667 • Letter: A

Question

A small airline company has just purchased a computer for itsnew automated reservations system. You have been asked to programthe new system. You are required to write an application thatassigns seats on each flight of the airline’s only plane(capacity: 30 seats). The plane has 10 rows of 3 seats each. 2 ofthese seats are window seats.

Your program should display the following alternatives:

           Please type 1 for First Class

           Please type 2 for Economy Class

           

If the user types 1, your program should assign a seat in thefirst class section (seats 1 -10). If the user types 2, yourprogram should assign a seat in the economy class section (seats11-30). Then ask the passenger about where he wants to sit:

           Do you want a window seat?

If the user type Y for yes then you have to allocate a windowseat for him. If the user type N for no then you have to allocate amiddle seat. Your program should also collect the name and thetelephone number of the passenger. Your program should then print aboarding pass indicating the person name, seat’s numberwhether it is in the first class or economy section of the planeand whether the seat is a window seat or not.

Use a two-dimensional array of type boolean to represent theseating chart of the plane. Initialize all the elements of thearray to false to indicate that all seats are empty. As each seatis assigned, set the corresponding element of the array to true toindicate that the seat is no longer available.

Your program should never assign a seat that has already beenassigned. When the economy section is full, your program should askthe person if it is acceptable to be placed in the first class (andvice versa). If yes, make the appropriate seat assignment. If no,print the message “Next flight leaves in 3 hours”. Alsoif there are no window seats available you should ask the passengerif he would like a middle seat.

Explanation / Answer

public classreservations
{
   
    // return the free seat in the first-classsection
    // if the first-class section is full return-1
    static int getFirstClassSeat(boolean[] chart){
        int s = -1;
        for(int i=0; i<5;i++)
           if(chart[i] == false)
               s = i;
        return s;
    }


    static int getEconomySeat(boolean[] chart) {
        int s = -1;
        for(int i=5; i<20;i++)
           if(chart[i] == false)
               s = i;
        return s;
    }
   
    public static void main (String[] args)
    {

        Scanner Choice=newScanner(System.in); //User chooses their preference
        String[] PassNames = newString[30];    //Array to hold persengers names
        boolean[] chart = newboolean[30];        //seatavailable in airplane
       
        for(int a = 0; a <PassNames .length; a++)    //loop to iterate througharray
        {
           chart[a] = false; //initialize all seat to false "Empty"
        }

        for(int i=0;i<PassNames.length; i++) {

           System.out.println("Please type 1 for First Class or Please type 2for Economy");
           int section = Choice.nextInt();
           
           if(section == 1) {
               if(getFirstClassSeat(chart) != -1) {
                   // assign a seat in the first-class section
               } else {
                   // ask the person if it is acceptable to be placed in theeconomy
                   String answer = Choice.next();
                   if(answer.equals("yes") && getEconomySeat(chart) != -1){
                       // assign a seat in the economy section
                   } else {
                       // display the message “Next flight leaves in threehours”
                   }
               }
           } else { // section == 2
               if(getEconomySeat(chart) != -1) {
                   // assign a seat in the economy section
               } else {
                   // ask the person if it is acceptable to be placed in thefirst-class
                   String answer = Choice.next();
                   if(answer.equals("yes") && getFirstClassSeat(chart) != -1){
                       // assign a seat in the economy section
                   } else {
                       // display the message “Next flight leaves in threehours”
                   }
               }
           }
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote