• 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

Loop airplane seating reservations until all seats taken or user hits 0

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I'm writing a classic airplane seating program. The program runs fine except for two things:

1) I want the user to exit the program when 0 is inputted (program also quits when all seats are reserved - this works fine already). Now the program quits when user hits blank line with enter. How to fix this and make 0 the exit key?
2) I would like for there to be a line below the seating chart saying that there are XX number of seats available. When user makes reservations, the line should update every time under the seating chart saying that there are such and such number of seats available. Any pointers on how to implement this?

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have far too much code all in the one method. You should have a method for everything you are doing. One method to set up the empty array, one to fill seats, one to count them, etc. You cannot make sense out of doing everything in one method. That includes exiting; you should have en exit method or at least a loop with a condition to continue when you don't enter 0.
Are you using the == operator to compare inputs? That is highly unlikely to work.

Why are you not using Seat objects?
 
Sam Petersen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not know what a Seat object is. I'm a beginner and my class just started a week ago, and we have not discussed objects yet. Nor have we talked about using multiple methods. So I'm afraid I do not quite understand what you are saying... The method link was interesting but I don't understand how I could part my code into different methods. Maybe I'll learn further down the road. Thanks for the tip though!
 
Ranch Hand
Posts: 235
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, for now, think of the Seats object as a place that tells you what a seat is -- rowNumber, seatNumber, isOccupied. From that you would then declare all the methods (read functions) that deal with all the things you can do to a seat. EmptySeat, FillSeat, InitializeAllSeats, PrintSeats.... all that cool stuff. Just something to keep in mind over the coming weeks as you progress in the class.

Now, as to your problem, I believe it's in your conditional statement in line 20. I would put in a println() to see what's in input, and its length.

Regards,
Robert
 
Sam Petersen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys!

I actually got the program to quit on user input 0. The second question is still unresolved but at least most of the program works!
 
Robert D. Smith
Ranch Hand
Posts: 235
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second part is pretty easy. You know how many totalSeats you have. You know how many filledSeats you have. And you want to display how many are left.

Best suggestion on how to solve this -- turn off your computer, get a pad of paper and a pencil (or three or four) and really good eraser. Write out the problem on paper, find the solution. Each step should go in its own method (paragraph). Once you have done that on paper, the writing the code part should be self evident.

Regards,
Robert
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic