Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AirlineRaservation {
- public static void main(String[] args) {
- int[] airline = new int[10]; // 1-5 first class , 6-10 economy class , capacity = 10.
- int counter = 0;
- Scanner input = new Scanner(System.in);
- while(counter < airline.length)
- {
- System.out.println("Enter number 1 for first class or number 2 for economy.");
- int num = input.nextInt();
- if(num == 1)
- {
- System.out.println("You want a first class ticket.");
- System.out.println("Which seet between 1 and 5 do you want ?");
- int seat = input.nextInt();
- if(seat <= 5)
- {
- boolean taken = false;
- for(int i = 0; i < airline.length; i++)
- {
- if(seat == airline[i])
- {
- taken = true;
- }
- }
- if(!taken)
- {
- airline[counter] = seat;
- counter++;
- System.out.println(seat + " is added.");
- }
- else
- {
- System.out.println(seat + " has been taken.");
- }
- }
- }
- if(num == 2)
- {
- System.out.println("You want an economy class ticket.");
- System.out.println("Which seet between 6 and 10 do you want ?");
- int seat = input.nextInt();
- if(seat <= 10 && seat >= 6)
- {
- boolean taken = false;
- for(int i = 0; i < airline.length; i++)
- {
- if(seat == airline[i])
- {
- taken = true;
- }
- }
- if(!taken)
- {
- airline[counter] = seat;
- counter++;
- System.out.println(seat + " is added.");
- }
- else
- {
- System.out.println(seat + " has been taken.");
- }
- }
- }
- System.out.println("The tickets you want are are: ");
- for(int i = 0; i < counter; i++)
- {
- System.out.println(airline[i] + " ");
- }
- System.out.println("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement