This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Array Problem....sort of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array Problem....sort of" Watch "Array Problem....sort of" New topic

Array Problem....sort of

Ben Kopel

Joined: Feb 25, 2007
Posts: 1
Howdy Ranchers...

This being one of my first Java projects, it's got me stumped. Basically, the project is this: An airline has 10 seats (First class 1-5, Economy 6-10). The user is prompted to enter 1 (for First) or 2 (for Economy). Once First or Economy is full, the user should be told it is full and asked whether it's ok to be seated in the non-full section. When both sections are full, it should display "Next flight leaves in 3..." message.

I've got most of it, but cannot figure out how to display and prompt the user with the message that one section is full, would they like to sit in the other (firstFullChoice).

Also, I was getting the Plane full message (Next flight leaves in 3...) before, but for some reason, that's not appearing anymore.

Any suggestions are very much welcome.

EDIT by mw: Added much-needed Code Tags.
[ February 25, 2007: Message edited by: marc weber ]
marc weber

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

Look at the flow of execution. Suppose the user asks for first class. If there's a seat available in first class (if firstClassseat != -1), it assigns it. But if not (else), it should ask the user if economy is okay. Instead, this code is just going ahead and assigning economy without asking. This is where you might call firstFullChoice.

Paying more attention to flow should get you past the main issue, although there are still some bugs with seat assignments. For example, in firstFullChoice, when the plane is full, it keeps assigning seat#0. Do you see why?

Also, it doesn't look like it's being used, but the firstClassFull method has an error in the for statement -- it should be i<5, rather than i>5.)
[ February 25, 2007: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Array Problem....sort of
It's not a secret anymore!