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

JAVA (Airline System) A small airline has just purchased a computer for its new

ID: 3826005 • Letter: J

Question

JAVA

(Airline System) A small airline has just purchased a computer for its new automated system. You have been asked to develop the new system. You are to write an application to assign seats on each flight of the airline’s planes.

Your application should display the following alternatives:

"Please type 1 for Roundtrip"

"Please type 2 for One-way"

Enter passenger’s information (name, gender, phone number,…etc)

Enter departure and destination airports

Enter depart and return date(if roundtrip)

Selection for the seat

If the user types 1, your application should provide inputs for both departure and destination airports and corresponding dates. If the user types 2, your application should only provide inputs for departure airport and depart date. Your application should also display a set of inputs for passenger information.

Use a one-dimensional array of primitive type boolean to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding elements of the array to true to indicate that the seat is no longer available. (Maxmuime seat :6 in the plane)

e plane)Your application should never assign a seat that has already been assigned. When plane is full, your application should display the message "This flight is full."

Requirements:

At least one abstract class

At least one interface

At least five concrete classes to make reservation, display passenger list, display seating chart(taken/empty), display charge for the passenger, and search passenger’s phone number by their name.

Explanation / Answer

#include <stdio.h>

int findFreeLocationFirstClass(int b[]);

int findFreeLocationEconomyClass(int b[]);

int isEmptyFirstClass(int b[]);

int isEmptyEconomyClass(int b[]);

void printBoardingPass(int seatNumber);

int arrangeAndPrintFirstClass(int b[],int counter);

int arrangeAndPrintEconomyClass(int b[],int counter);

int main(void) {

int choice=0;

int seats[11]={0};

static int countFirstClass=0;

static int countEconomyClass=0;

int emptyEconomyClassLocation=0;

int emptyFirstClassLocation=0;

int freePlace=0;

char charChoice=8;

while (choice!=-1)

{

printf("Please type 1 for first class(-1 to exit)(%d First Class Available) :",5-countFirstClass);

printf(" Please type 2 for economy class(-1 to exit)(%d Economy Class Available) :",5-countEconomyClass);

scanf("%d",&choice);

if (choice==1 && isEmptyFirstClass(seats)) {

}

else if (choice==2 && isEmptyEconomyClass(seats)) //ok

{             

countEconomyClass=arrangeAndPrintEconomyClass(seats,countEconomyClass);

else {

printf(" Next flight leaves in 3 hours. ");

if(choice==1 && (5-countEconomyClass)>0 ){

printf("or You can choose Economy Class if you want. We have empty places in there. (y or n) : ");

scanf(" %c",&charChoice);

if (charChoice=='y')

{

countEconomyClass=arrangeAndPrintEconomyClass(seats,countEconomyClass);

}

else printf("Good Bye");

}

else if (choice==2 && (5-countFirstClass)>0 )

{

printf(" r You can choose First Class if you want. We have empty places in there. (y or n) : ");

scanf(" %c",&charChoice);

if (charChoice=='y')

{

countFirstClass=arrangeAndPrintFirstClass(seats,countFirstClass);

}

else printf("Good Bye");

}

else {

printf(" Next flight leaves in 3 hours. ");

}

getch();

return 0;

}

}

}

int findFreeLocationFirstClass(int b[]){

int i;

for (i = 1; i <=5 ; i++)

{

if(b[i]==0)

return i;

}

printf(" No place left in First Class ");

getch();

exit(1);

}

int findFreeLocationEconomyClass(int b[])

{

int i;

for (i = 6; i <=10 ; i++)

{

if(b[i]==0)

return i;

}

printf(" No place left in Economy Class");

getch();

exit(1);

}

int isEmptyFirstClass(int b[])

{

int i;

for (i = 1; i <=5 ; i++)

{

if(b[i]==0)

return 1;

}

return 0;

}

int isEmptyEconomyClass(int b[])

{

int i;

for (i = 6; i <=10 ; i++)

{

if(b[i]==0)

return 1;

}

return 0;

}

void printBoardingPass(int seatNumber)

{

printf("Seat Number %d is reserved for you. Have a nice and safe flight. ",seatNumber);

}

int arrangeAndPrintFirstClass(int b[],int counter)

{

int freePlace=0;

int countFirstClass=counter;

freePlace=findFreeLocationFirstClass(b);

b[freePlace]=1;

printBoardingPass(freePlace);

countFirstClass++;

return countFirstClass;

}

int arrangeAndPrintEconomyClass(int b[],int counter){

int freePlace=0;

int countEconomyClass=counter;

freePlace=findFreeLocationEconomyClass(b);

b[freePlace]=1;

printBoardingPass(freePlace);

countEconomyClass++;

return countEconomyClass;

}