Vous êtes sur la page 1sur 3

6/13/13

Alphabet Pyramid (Beginning Java forum at JavaRanch)

Big Moose Saloon


A friendly place for programming greenhorns!
Search

Java FAQ

Recent Topics

Register / Login

A special promo: Enter your blog post or vote on a blogger to be featured in an upcoming Journal

JavaRanch Java Forums Java Beginning Java

Author

Alphabet Pyramid
posted 2/16/2005 10:08 AM

David J. Gonzo Greenhorn 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.... 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 airlines only plane (capacity: 10 seats). Your program should display the following menu of alternatives lease type 1 for smokingPlease type 2 for nonsmokingIf 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 persons 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.

www.coderanch.com/t/398579/java/java/Alphabet-Pyramid

1/3

6/13/13

Alphabet Pyramid (Beginning Java forum at JavaRanch)

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");} } }

David O'Meara Rancher Joined: Mar 06, 2001 Posts: 13459


I like...

posted 2/16/2005 10:17 AM

"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! Dave

David J. Gonzo Greenhorn Joined: Feb 15, 2005

posted 2/16/2005 10:47 AM

Yes I made the changes to my profile. I am new to this forum and was unaware
2/3

www.coderanch.com/t/398579/java/java/Alphabet-Pyramid

6/13/13

Alphabet Pyramid (Beginning Java forum at JavaRanch)

Posts: 20

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.

apologies,

Ilja Preuss author Sheriff Joined: Jul 11, 2001 Posts: 14112

posted 2/16/2005 2:56 PM

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

Granny's Programming Pearls "inside of every large program is a small program struggling to get out" JavaRanch.com/granny.jsp

subject: Alphabet Pyramid

Similar Threads A simple boarding pass.... Assignment print invalid selction not working Array Problem....sort of Need some help with Java program Airline.java
All times above are in your local time zone & format.T he current ranch time (not your local time) is Jun 13, 2013 04:16:39 .

Contact Us | Powered by JForum |

C opyright 1998-2013 Paul W he aton

www.coderanch.com/t/398579/java/java/Alphabet-Pyramid

3/3

Vous aimerez peut-être aussi