Advertisement
vp0415

lec5.3

Nov 13th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AirlineRaservation {
  4.  
  5.     public static void main(String[] args) {
  6.         int[] airline = new int[10]; // 1-5 first class , 6-10 economy class , capacity = 10.
  7.         int counter = 0;
  8.         Scanner input = new Scanner(System.in);
  9.         while(counter < airline.length)
  10.         {
  11.             System.out.println("Enter number 1 for first class or number 2 for economy.");
  12.             int num = input.nextInt();
  13.             if(num == 1)
  14.             {
  15.                 System.out.println("You want a first class ticket.");
  16.                 System.out.println("Which seet between 1 and 5 do you want ?");
  17.                 int seat = input.nextInt();
  18.                 if(seat <= 5)
  19.                 {
  20.                     boolean taken = false;
  21.                     for(int i = 0; i < airline.length; i++)
  22.                     {
  23.                         if(seat == airline[i])
  24.                         {
  25.                             taken = true;
  26.                         }
  27.                     }
  28.                     if(!taken)
  29.                     {
  30.                         airline[counter] = seat;
  31.                         counter++;
  32.                         System.out.println(seat + " is added.");
  33.                     }
  34.                     else
  35.                     {
  36.                         System.out.println(seat + " has been taken.");
  37.                     }
  38.                 }
  39.             }
  40.             if(num == 2)
  41.             {
  42.                 System.out.println("You want an economy class ticket.");
  43.                 System.out.println("Which seet between 6 and 10 do you want ?");
  44.                 int seat = input.nextInt();
  45.                 if(seat <= 10 && seat >= 6)
  46.                 {
  47.                     boolean taken = false;
  48.                     for(int i = 0; i < airline.length; i++)
  49.                     {
  50.                         if(seat == airline[i])
  51.                         {
  52.                             taken = true;
  53.                         }
  54.                     }
  55.                     if(!taken)
  56.                     {
  57.                         airline[counter] = seat;
  58.                         counter++;
  59.                         System.out.println(seat + " is added.");
  60.                     }
  61.                     else
  62.                     {
  63.                         System.out.println(seat + " has been taken.");
  64.                     }
  65.                 }
  66.             }
  67.                 System.out.println("The tickets you want are are: ");
  68.                 for(int i = 0; i < counter; i++)
  69.                 {
  70.                     System.out.println(airline[i] + " ");
  71.                 }
  72.                 System.out.println("\n");
  73.            
  74.         }
  75.  
  76.     }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement