I am writing a program (no gui) for assigning customers to airline seating. I have included the requirements from my instructor. Looking for advice about how I have approached things. I am currently getting a compile error that sticks on the 'catch' statement. I can't figure it out. Any comments, advice, or code examples would be greatly appreciated. Thank You ahead of time, this forum has been a great help to my
Java beginnings, although I am still a newbie, I will one day help others here, as others have helped me....
Code:
--------------------------------------------------------------------------------
/*POS 407February 15Week Four DQ Part IIRequirements:A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system in Java. You are to write a program to assign seats on each flight of the airline�s only plane (capacity: 10 seats). Your program should display the following menu of alternatives
lease type 1 for �smoking�Please type 2 for �nonsmoking�If the person types 1, then your program should assign a seat in the smoking section (seats 1-5). If the person types 2, then your program should assign a seat in the nonsmoking section (seats 6-10). Your program should then print a boarding pass indication the person�s seat number and whether it is in smokingor nonsmoking section of the plane. Use a single subscript array to represent the seating char of the plane. Initialize all the elements of the array to 0 to indicate all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.Your program should, of course, never assign a seat that has already been assigned. When the smoking section is full, your program should ask the person if it is acceptable to be placed in the nonsmoking section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message �Next flight leaves in 3 hours�*/ import java.io.*; import java.util.*; import java.lang.*; public class boardingPass{ public static void main(
String[] arguments) { String[] booking = new String[9]; int userInput; int yesNo; int i = 0; System.out.println("Please type 1 for 'smoking' section or 2 for 'non-smoking' section. Press 'enter' when done."); try{//try open userInput = System.in.read();//a bit of error checking, but I need a little more... while( i <= 10){//for open if(userInput == 1){//if open for(int s = 0; s <= 5; s++){//for open System.out.println("Boarding Pass: Smoking Seat:" + booking[s]); System.out.println("Would you like to book another seat? [y/n]. Press 'enter' when done."); yesNo = System.in.read(); if(yesNo == 'y') return; else System.exit(0); i++; }//for close }//if close else{//else open for(int n = 5; n <= 10; n++){//for open System.out.println("Boarding Pass: Non-Smoking Seat:" + booking[n]); System.out.println("Would you like to book another sear? [y/n]. Press 'enter' when done."); yesNo = System.in.read(); if(yesNo == 'y') return; else System.exit(0); i++; }//for close }//else close System.out.println("Next flight leaves in 3 hours"); }//for close }catch(Exception e){ System.out.println("error"); } finally{ System.out.println("Thank You");} } }