• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array Problem....sort of

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic