File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes  Alphabet Pyramid Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

Alphabet Pyramid

David J. Gonzo

Joined: Feb 15, 2005
Posts: 20
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....

/*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*; 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 =;//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 =; 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 =; 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");} } }
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

"david dee oh double gee",
while we're an extremely friendly and helpfull bunch here at the 'Ranch, we do have our limits.

Firstly your display name is invalid. Please edit your profile and fix your display name it that it has your first name, a space, then your last name. Invalid account get deleted.

Secondly, you'll need to format that mess before anyone will even attempt to look at it. Using the UBB 'code' tags will also help (you'll see them at the bottom of the page when you edit your post)

Lastly, this looks like homework. You'll find we're quite happy to give pointers and lead you to a solution, but at no stage will a solution be provided. If someone does post a solution, usually a moderator will delete it.

Best of luck and welcome to the JavaRanch!

David J. Gonzo

Joined: Feb 15, 2005
Posts: 20
Yes I made the changes to my profile. I am new to this forum and was unaware how it would post my 'paste'. It won't happen again...

It is an assignment, but I have all of the code compiling but just have a problem with the right half of the pyramid.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Continue discussion here.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Alphabet Pyramid
It's not a secret anymore!