• 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

Class Project: Airline Reservation System

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Greenhorns! I've been working this project for a few weeks now, and have hit a small snag. But let me start from the beginning - here's the actual assignment:

Write a program to book seats on a small airplane. The plane has four rows each with 3 seats. Initially all seats are available and are labeled Seat 1 through Seat 12. Create a graphical user interface for this assignment. Use an array of 12 labeled buttons to represent the seats. The program should be event driven.

When a button is clicked, a confirmation dialog box must be displayed. This dialog box must have yes, no, and cancel buttons. If the yes button is clicked, then the label is changed to indicate that the seat is booked. If either the no or cancel button is clicked the dialog box closes and no additional action is taken. After the last seat has been reserved, the program must display a message box indicating that all seats have been booked.

If a button marked as booked is clicked, then the program must display a dialog box indicating that the seat is booked and another seat must be selected. This dialog box requires an OK button only. Note: If you would like to add "unbook" functionality to the program you may do so for extra credit. The user must have an authorization code to "unbook" a seat.

Create an exit button to terminate the program. If the user clicks the exit button, a dialog box must be displayed to confirm that the user really wants to quit the program. The confirmation dialog box must have yes, no, and cancel buttons. If the user clicks the yes button then the GUI closes and the program ends.

Create separate panels for an instructional area (labels that contain instructions for the user), the seat buttons, and the exit button. Use layout managers to arrange the labels in the instructional panel and the seat buttons in the seat panel.

The frame title bar must display a heading that represents the name of your application (for example, Acme Airline Reservation System).

Your program must write the button labels to a file when the program terminates. It must also read the labels from the file (if the file exists) when a new session begins so that the button labels are reset to what they were when the previous session ended. The program must also set a seat counter to accurately reflect the number of occupied seats.

So far, this has been a relatively easy task. The only thing I'm really having trouble with so far is this section:

If a button marked as booked is clicked, then the program must display a dialog box indicating that the seat is booked and another seat must be selected. This dialog box requires an OK button only. Note: If you would like to add "unbook" functionality to the program you may do so for extra credit. The user must have an authorization code to "unbook" a seat.

The specific trouble that i'm having is that once i've "booked" a seat, the "seat already booked" confirm dialog box will not go away, no matter which button i press. i must resort to hitting the stop button in the netbeans output window.

so my question is: how do i get that window to:

a. close when i click "no" or "x"

b. remove a seat's "reserved" status when i click "yes"

thank you all very much in advance!!

here's my code so far:
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your for loops may be messing you up:



You know which button has been pressed by e.getSource, so there's no need to do either for loop. In your second for loop above, you're changing the text and actioncommands of all buttons (note that your program doesn't truly get locked but rather you must deal with 12 dialogs before the dialogs will quit).

Myself, I'd create a class, say called ReservationSeat, that holds a boolean variable, booked, an int, seatNumber, an int (or better String) variable, confirmationNumber, give it requisite setters and getters, and either create a 2-dimensional array of these guys or perhaps associate JButtons with these objects by using a HashMap<JButton, ReservationSeat>.

e.g.,


If you used a HashMap, then your button listener can be greatly simplified. i.e.,


Note the similar post here: Reservation Java Project

Classmate?
 
reply
    Bookmark Topic Watch Topic
  • New Topic