This is what the assignment is: (Airline Reservations System) A small airline has just purchased a computer for its new automated reservations 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 only plane (capacity: 10 seats).
Your application should display the following alternatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, your application should assign a seat in the first-class section (seats 15). If the user types 2, your application should assign a seat in the economy section (seats 610). Your application should then display a boarding pass indicating the person's seat number and whether it is in the first-class or economy section of the plane.
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.
Your application should never assign a seat that has already been assigned. When the economy section is full, your application should ask the person if it is acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours."
It doesn't seem to work and I don't get what is wrong with it. It doesn't show if the seats are full. What do I do to fix it?

Here is my code:

import java.util.Scanner;

public class Airline_Reservation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean seats [] = new boolean[10];
int firstClass = 1;
int econClass = 6;
int option;

for(int count = 1; count <= 10;){
System.out.print("Where would you like to be seated? (1 = First Class and 2 = Economy): ");
option = input.nextInt();

if(option == 1){
if(firstClass <= 5){
seats[firstClass++] = true;
System.out.printf("Your seat number for First Class is: %d\n", count);
}
}
if(seats[econClass++] = false){
System.out.print("Sorry, but first class is full.");
if(econClass < 10){
System.out.print("Would you like to go to Economy? (1 = yes and 2 = no): ");
int selection = input.nextInt();
if(selection == 1){
seats[econClass++] = true;
System.out.printf("You have a seat in Economy which is seat: %d\n", count);
}
else
System.out.print("Next flight leaves in 3 hours!");
break;
} 
}

else if(option == 2){
if(econClass < 10){
seats[econClass++] = true;
System.out.printf("Your seat number for Economy is: %d\n", count);
}
}
if(seats[econClass++] = false){
System.out.print("Sorry, but Economy is full.");
if(firstClass <= 4){
System.out.print("Would you like to go to First Class? (1 = yes and 2 = no): ");
int selection = input.nextInt();
if(selection == 1){
seats[firstClass++] = true;
System.out.printf("You have a seat in First Class which is seat: %d\n", count);
}
else
System.out.print("Next flight leaves in 3 hours!");
}
}
}
}
}

Forgot to mention, it only chooses the number one for the seat number it doesn't randomize them.

One thing that jumps out is that you seem to be using values 1-10 as indexes for your array, but Java arrays are zero-based - the valid indexes are 0-9

stopped reading when I noticed the entire thing was a single massive method...
Were I the teacher here I'd give it minimum marks just because of that.

it only chooses the number one for the seat number it

Have another look at the print statements where you try to print the seat number. Which value do you actually print? ;)

JamesCherrill I realized that after I posted this XD Thanks for telling me. Also I did not know it was 0-9 in Java. And jwenting I didn't know that cuz I thought that's how you do 'if' 'else' statements.

This article has been dead for over six months. Start a new discussion instead.