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

The program you will create is to allow a user to enter the type of seats on an

ID: 3823455 • Letter: T

Question

The program you will create is to allow a user to enter the type of seats on an airplane they would like (first class, business class, coach, economy) and you will write the code that will prompt them for the category they want to purchase and you will print out the number of seats available for that type of seat category. You will use the 2 parallel arrays, seats[] ={5, 3,1,2} and price[] ={1200, 850, 600, 450} ; seats[] represents the number of seats available for each category – seats[0] = 5, which means there are 5 seats available in first class. seats[1] = 3 which means there are 3 seats available in business class, etc.   price[] represents the price for each of these categories of seats: price[0] = 1200 which means a first class seat costs 1200 dollars

The output should look like

Welcome to Delta Airlines!

Please enter the amount of money you have to spend on a seat:

550

  

You can buy a seat in category 3.

Which category would you like to inquire about?

0

Category 0 has 5 seats available

Would you like a seat in category 0?

No

Which category would you like to inquire about?

1

Category 1 has 3 seats available

Would you like a seat in category 1?

Yes

Thank you for flying with us! You have a seat in category 1 for 850 dollars

New values for arrays:

seats[] = 5 2 1 2

prices[] = 1200 850 600 450

Explanation / Answer

class DeltaAirlines{

public static void main(String args[]){

Scanner in = new Scanner(System.in);

int N=4;

int [] seats ={5, 3,1,2};

int[] price ={1200, 850, 600, 450} ;

String[] SeatNames={"first class", "business class", "coach", "economy"};

System.out.println("Welcome to Delta Airlines !! Please enter the amount of money you have to spend on a seat:");

int amount=in.nextInt();

System.out.println("You can buy a seat in category (-ies): ";

int[] indexArray=new int[N];

for(int i=0,j=0;i<N;i++)

{ if(amount<price[i]) {

indexArray[j++]=i; // for tracking

}

System.out.println(indexArray); // output categories

System.out.println("Which category would you like to inquire about?");

int category=in.nextInt();

System.out.println("Category "+category+" has "+seats[i]+" seats");

System.out.println("Would you like a seat in category "+category+" ?");

String ans= in.nextLine();

if(ans=="No") // repeat

else if (ans=="Yes"){

//print Thank you for flying with us!

}

//update arrays

Thanks !!