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 airlines 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 1—5). If the user types 2, your application should assign a seat in the economy section (seats 6—10). 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.’


* FileName: AirlineRS.java
* @author (Sandeep Negi)
* MCA 2nd Year
* Java Programming Lab-406

import java.util.Scanner;

class AirlineRS {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
boolean seats[] = new boolean[10];
int seatsFull = 0,seatFound,seatCount;

for(int i=0;i<10;i++){
seats[i] = false;
seatCount = 0;
for(int i=0;i<10;i++){
if(seats[i] == false) seatCount++;
if(seatCount < 1){
System.out.print("\nAll seats are sold for this flight.");
seatsFull = 1;
System.out.print("\n" + seatCount + " seats are availabe.");
System.out.print("\nPress 1 for first class or 2 for economy class :");
int seatClass = sc.nextInt();


case 1: seatFound = 0;
//for first class
for(int i=0;i<5;i++){
if(seats[i] == false){
seats[i] = true;
System.out.print("\nBoarding Pass Details -->");
System.out.print("\nSeat number :" + (i+1));
System.out.print("\nFirst Class");
seatFound = 1;


case 2: seatFound = 0;
//for economy class
if(seatFound == 0){
for(int i=5;i<10;i++){
if(seats[i] == false){
seats[i] = true;
System.out.print("\nBoarding Pass Details -->");
System.out.print("\nSeat number :" + (i+1));
System.out.print("\nEconomy Class");
seatFound = 1;

default: System.out.print("\nInvalid input...");seatFound = 0;

if(seatFound == 0){
System.out.print("\nNo seats availabe in this class, would you like to travel in another class(y/n):");
String changeSeatClass = sc.nextLine();

}while(seatsFull != 1);
System.out.print("\nNext Flight leaves in 3 hours..");

About these ads
  1. suma
    April 11, 2012 at 11:05 am

    this what i was looking for its simple and easy to understand i thank the one who write it ^___^
    so helpful

  2. Samuel
    November 25, 2012 at 12:42 pm

    U saved my day. Exactly what i was looking 4. Thenx

  3. aliye
    December 15, 2012 at 9:55 pm

    yes i think this is simple and understandable. thanks

  4. Martin
    April 16, 2013 at 9:40 am

    Could you use queues to do checking in or it would be uncalled for because the plane is small?

  5. July 9, 2013 at 12:12 am

    Superb post however I was wondering if you could write a litte more on this subject?
    I’d be very grateful if you could elaborate a little bit more. Bless you!

  6. mimi
    August 5, 2013 at 12:46 am


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: