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

For this lab we will simulate an airplane seating chart system. The program will

ID: 3539393 • Letter: F

Question

For this lab we will simulate an airplane seating chart system. The program will initially start with an empty airplane. The system will ask seating preferences (such as window, isle seat, section of the plane) as well as how many tickets. Based on availability and seating preferences, the program will choose the seats, display a diagram and the coordinates. The system should also allow for a customer pick a specific seat. Assume that the middle 3 rows in section 2 are wing seats. Keep in mind: 1. That you should try to group passengers together if they are travelling together 2. If they do not choose specific seats, then choose by preferences 3. You may also want to have a method for placing passengers in the next available spot, if there are no preferences 4. You should display the current availability of the seats (O for Empty, X for occupied) 5. Break down the program into methods as much as possible. Extra Credit: Also store specific details of each passenger, along with their seating chart. The seating chart can look something like: ---------- / // \ | OOO OOO| | OOO OOO| Section 1 | OOO OOO| | OOO OOO| | OOO OOO| | OOO OOO| | OOO OOO| | | | OOO OOO| | OOO OOO| | OOO OOO| Section 2 | OOO OOO| | OOO OOO| | | | OOO OOO| | OOO OOO| | OOO OOO| Section 3 | OOO OOO| | OOO OOO| | OOO OOO|

Explanation / Answer

There are 2 files:

Airplane.java and

Customer.java



Airline.java




import java.io.*;
import java.util.*;

public class Airline {
    public static char[][] A = new char[20][6];

    Airline(){
        //A = new char[20][6];
    }
   
    public static void main(String[] args) throws IOException{
       
        //Airline a1 = new Airline();
        for(int i=0; i<20; i++)
            for(int j=0; j<6; j++)
                A[i][j]='O';
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        ArrayList <Customer> list = new ArrayList<Customer>();
       
        while(true){
            System.out.println("New Booking?? Y/N");
            String ans = bf.readLine();
            if(ans == "N")
                break;
            Customer c = new Customer();
            takeInput(c);
            list.add(c);
           
        }

    }
   
    private static void takeInput(Customer c) throws IOException{
        printSeating();
        c.takeInput();
        seatAllotment(c);
    }
   
    private static void seatAllotment(Customer c) throws IOException{
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Do you have a specific seat choice? Y/N");
        String ans = bf.readLine();
        if(ans.equals("Y")){
            String book = "Y";
            while(book.equals("Y")){
                System.out.println("Enter Row:");
                int row = Integer.parseInt(bf.readLine());
                System.out.println("Enter Seat(s):");
                String seat = bf.readLine();
                bookSeat(row, seat, c);
                System.out.println("More Seats?? Y/N");
                book = bf.readLine();
            }
           
        }
        else{
            allotNextSeat(c);
        }
    }
   
    private static boolean allotNextSeat(Customer c){
        //System.out.println(c.sectionPreference+" "+c.seatPreference+" "+c.ticketNumber);
        if(c.ticketNumber>3){
            int ticket = c.ticketNumber;
            int temp = c.ticketNumber;
            while(temp>3){
                c.ticketNumber=3;
                allotNextSeat(c);
                temp-=3;
            }
            c.ticketNumber=temp;
            allotNextSeat(c);
            c.ticketNumber=ticket;
        }
        outer: for(int i=0; i<20; i++){
            for(int j=0; j<6; j++){
                //System.out.println(i+" "+j);
                if(c.ticketNumber == -1)
                    if(A[i][j]=='O'){
                        A[i][j]='X';
                        return true;
                    }
                if(c.sectionPreference == 1)
                    if(i>=5)
                        continue outer;
                if(c.sectionPreference == 2)
                    if(i<5 || i>13 )
                        continue outer;
                if(c.sectionPreference == 3)
                    if(i<14)
                        continue outer;
                if(c.seatPreference == 1)
                    if(!(j==2 || j==3))
                        continue;
                if(c.seatPreference == 2)
                    if(!(j==0 || j==5))
                        continue;
                if(c.seatPreference == 3)
                    if(!(j==1 || j==4))
                        continue;
               
                if(c.ticketNumber == 0)
                    return true;
               
                if(c.ticketNumber ==1){
                    if(A[i][j]=='O'){
                        A[i][j]='X';
                        char ch = (char)((int)'A'+j);
                        String set = c.seat+(i+1)+ch;
                        c.setSeat(set);
                        return true;
                    }
                }
                if(c.ticketNumber ==2){
                    if(A[i][j] == 'O'){
                        if(j==0 || j==1 || j==3 || j==4)
                            if(A[i][j+1] == 'O'){
                                A[i][j]= 'X';
                                A[i][j+1] = 'X';
                                return true;
                            }
                        if(j==1 || j==2 || j==4 || j==5)
                            if(A[i][j-1] == 'O'){
                                A[i][j]= 'X';
                                A[i][j-1]= 'X';
                                return true;
                            }   
                    }
                }
                if(c.ticketNumber == 3){
                    System.out.println("Enters here!!!");
                    if(A[i][0]=='O' && A[i][1]=='O' && A[i][2]=='O'){
                        A[i][0]='X';
                        A[i][1]='X';
                        A[i][2]='X';
                        return true;
                    }
                    if(A[i][3]=='O' && A[i][4]=='O' && A[i][5]=='O'){
                        A[i][3]='X';
                        A[i][4]='X';
                        A[i][5]='X';
                        return true;
                    }
                }
               
            }
        }
        if(c.ticketNumber == 3){
            c.ticketNumber = 2;
            allotNextSeat(c);
            c.ticketNumber = 1;
            allotNextSeat(c);
            c.ticketNumber = 3;
        }
        if(c.ticketNumber == 2){
            c.ticketNumber =1;
            allotNextSeat(c);
            allotNextSeat(c);
            c.ticketNumber = 2;
        }
        if(c.ticketNumber == 1){
            c.ticketNumber = -1;
            allotNextSeat(c);
            c.ticketNumber = 1;
        }
        return false;
    }
   
    private static void bookSeat(int row, String s, Customer c) throws ArrayIndexOutOfBoundsException{
        for(int i=0; i<s.length(); i++){
            A[row-1][(s.charAt(i)-'A')] = 'X';
            String set = c.seat+row+s.charAt(i);
            c.setSeat(set);
        }
    }
   
    private static void printSeating(){
        for(int i = 0; i<20; i++){
            System.out.print((i+1)+" ");
            System.out.print("|"+A[i][0]+A[i][1]+A[i][2]+"| |"+A[i][3]+A[i][4]+A[i][5]+"|");
            if(i==8 || i==9 || i==10)
                System.out.print("xxx Wing Seat xxx");
            System.out.println();
            if(i==4)
                System.out.println("------Section A------");
            if(i==13)
                System.out.println("------Section B------");
            if(i==19)
                System.out.println("------Section C------");
        }
    }
   

}






Customer.java




import java.io.*;

public class Customer {
    public int seatPreference;
    public int sectionPreference;
    public int ticketNumber;
    public String seat;
    public void takeInput() throws IOException{
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Do you have a seating preference?? Y/N");
        char ans = bf.readLine().charAt(0);
        String s = Character.toString(ans);
        //System.out.println((s!="N"));
        if(!s.equals("N")){
            System.out.println("What is your seating preference??");
            System.out.println("1-Aisle 2-Window 3-Middle");
            this.seatPreference = Integer.parseInt(bf.readLine());
            System.out.println("What is your section preference??");
            System.out.println("1-Section A 2-Section B 3-Section C");
            this.sectionPreference = Integer.parseInt(bf.readLine());

        }
        System.out.println("How many tickets do you want?");
        this.ticketNumber = Integer.parseInt(bf.readLine());
    }
    void setSeat(String s){
        this.seat = s;
    }
}

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