I have a program that adds passengers to a seating chart. I have a first class array and a second class array.
In my main class, option 1 to add a passenger. Right now im trying to get it working for 1 passenger and then i'll move getting it with up 2 passengers at a time for first class and up to 3 passengers at a time for economy class. Which if done in groups, it need to be on side same side and same row and give back an error msg.
Heres my problem. When im done adding the first seat it goes back to the airline class for the main menu which asks if the user wants to add more passengers. If so then it goes back to the Reservation class, but then the first and economy class array are set back to blank. I need to somehow keep the information that has already been added and build onto that array. As you see i tried using tempArray to figure it out, but can't seem to get it working.
Heres the main Airline class
[ April 02, 2007: Message edited by: Jon Martin ] [ April 02, 2007: Message edited by: Jon Martin ]
Look closely at what it is that is being zero'd out each time.
Also, would it be worthwhile to have a separate seat class and then have your reservation object hold two arrays (first and second class) of seat objects? [ April 02, 2007: Message edited by: pete stein ]
The error is not hard to find. Look at everywhere you are calling your object's constructor. Each time you call a constructor the object starts afresh. That is why I wonder if you need a "seat" class that you can initialize instead.
Ok, with that working I came across one more problem.
If I choose display the seating chart before adding any seat, I get back null. I figured before the arrays are not initialized, but even if I add some passengers and display the seating chart I get back null. Any suggestions?
I've noticed several things of concern in your code:
In your airline class you have two distinct objects, reserveSeat an object of Reservation Class) and seatingClass an object of SeatingChart Class which is a child of the Reservation class. When you are adding reservations, all of your interactions are with the reserveSeat object, never with the SeatingClass object. The seatingClass object can't output any useful information if no information has been stored into it.
I don't see the purpose that the SeatingChart class serves, and why it is a child class of Reservation when it inherits no methods and no states from the parent class.
Your child class (SeatingChart) contains an instance of the parent class (Reservation) object called displaySeat. In SeatingChart's (the child object's) initialization code you instantiate the displaySeat object, and then in the constructor you call its display method. I think that you assume that the displaySeat object, since it is an instance of the parent Reservation class will automatically have all of the information from the reserveSeat object (another Reservation class object contained in the main method of the Airline class), but this assumption is wrong. Each object is unique and contains its own independent non-static information.
I am no expert on OOP design, so I can only tell you so much, but I believe that your overall object model is broken and that you should rethink the object model design from square one. Possible ideas include:
Have a Seat class that contains a boolean "occupied" variable, a "seatNumber" String var, a "passengerName" String var and a "seatingLevel" variable (i.e., first or second class).
An class called seatingLevel that holds arrays of seats and methods to access them, change them, and display them, can display number of seats available,...
An airplane class that holds two instances of seatingLevel, one for first class and one for coach.
There are many possible iterations that you could use. You might even want to put this project on hold for a bit and restudy a chapter or two on object oriented design before redesigning this. Learn how the pros do it first. I recommend Just Java or Head First Java as good beginners texts, but there are many others that are worthwhile too.
ps: have you thought about joining the Cattle Drive here? I have recently done just that and am learning quite a bit. [ April 04, 2007: Message edited by: pete stein ]
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad: