import java.io.*; public class AirlineReservation { static boolean[] seats = new boolean[10]; static BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in),1); public static void main (String[] args) throws IOException { String choice, again = "Y"; int ichoice, start = 0, end = 9; for (int i = 0; i < seats.length; i++) { seats[i] = false; } do { System.out.println("\nWhat type of seat do you want? "); System.out.println("\t1 for smoking\n\t2 for nonsmoking:" + "\n\tType Q to quit"); choice = stdin.readLine(); if (choice.toUpperCase().equals("Q")) { System.exit(1); } ichoice = Integer.parseInt(choice); if ((ichoice == 1) || (ichoice == 2)) { if (ichoice == 1) { start = 0; end = 5; } else { start = 5; end = 10; } int found = findSeat(start, end); if (found > 0) { System.out.println("\nFlight 123 Leaves at 3:00 am" + " from gate 345.\nYour seat is number: " + found); } else { System.out.println("\nNo Seats!" + "\nNext flight leaves in 3 hours"); } System.out.println("\nDo you want to reserve another seat?" + "\nType Y for yes."); again = stdin.readLine(); } else { System.out.println("\nPlease enter either 1 or 2."); } }while (again.toUpperCase().equals( "Y" )); System.out.println("\nThanks for flying with Crash Airways"); }//main public static int findSeat( int start, int end) throws IOException { String alternative; while (true) { int found = -1; for (int i = start; i < end; i++) { if (!seats[i]) { found = i + 1; seats[i] = true; return found; } } if (start == 0) { System.out.println("\nNo seat found in smoking " + "how about nonsmoking? Enter Y for yes."); alternative = stdin.readLine(); if (!alternative.toUpperCase().equals("Y")) { return found; } else { start = 5; end = 10; } } else { System.out.println("\nNo seat found in nonsmoking " + "how about smoking? Enter Y for yes."); alternative = stdin.readLine(); if (!alternative.toUpperCase().equals("Y")) { return found; } else { start = 0; end = 5; } } }//loop }//findSeat }//class