Sie sind auf Seite 1von 3

import java.utiil.

Scanner;
public class airline
{
boolean[] seating = new boolean[11] ;
Scanner sc = new Scanner(System.in);

public void start()


{
while ( true )
{
makeReservation();
}
}

public void makeReservation()


{
System.out.println( " Select the class \n 1.First Class \n 2.Economy Class" );
int airclass = sc.nextInt();
if ( airclass == 1 )
{
firstClass();
}
else
{
ecoClass();
}
}

public void firstClass() // assign a first class seat

for ( int count = 1; count <= 5; count++ )

if ( seating[count] == false ) // if false, then a seat is available for


assignment

seating[count] = true; // assign seat

System.out.println("First Class Seat \n", count);

break;

}
else if ( seating[5] == true ) // If seating[5] is true then first class is
fully booked

if ( seating[10] == true) // If seating[10] is true then economy (and


therefore whole flight) is fully booked

System.out.println("Sorry, flight fully booked. Next flight is in 3


hours.");

}
else // ask passenger if they would like an economy ticket instead

System.out.println("First Class is fully booked. Would you like Economy?


1 for Yes 2 for No");
int choice = input.nextInt();

if ( choice == 1 )
{

economySeat();

start();

}
else

System.out.println("Next flight is in 3 hours.");

System.exit(0);

}
}

public void economySeat() // assign an economy seat

for ( int count = 6; count <= 10; count++ )

if ( seating[count] == false ) // if false, then a seat is available for


assignment

seating[count] = true; // assign seat

System.out.printf("Economy. Seat\n", count);

break;

else if ( seating[10] == true ) // If seating[10] is true then economy


is fully booked

{
if ( seating[5] == true) //
{

System.out.println("Sorry, flight fully booked. Next flight is


in 3 hours.");

System.exit(0);

else // ask if passenger would like a first class ticket instead

System.out.println("Economy is fully booked. Would you like


First Class? 1 for Yes 2 for No");

int choice = input.nextInt();

if ( choice == 1 )

firstClassSeat();

start();

else

System.out.println("Next flight is in 3 hours");

System.exit(0);

Das könnte Ihnen auch gefallen