Lab 5: Arrays

Due: 10pm Tuesday March 8

Purpose: In this assignment, you will learn how to use arrays. You will create arrays, access their elements with index expressions, and iterate through arrays to access all their elements.



You will write a Java class Flight. This class will represent a flight and will have an associated code (a String), a list of passengers (an array of String), and a list of seats (an array of int). This class will provide the following functionality to the user: It will allow insertion of new passengers, swapping of passenger seats, displaying the seat of a specific passenger and also displaying the full list of passengers. A sample execution of the program is the following:

Enter code of flight: F1
Input number of passengers for flight: 6

System Menu
=============
1) Find Seat of Passenger
2) Set Passenger at a seat
3) Swap Passenger Seats
4) Print List Of Passengers
5) Exit
2
Enter seat number: 2
Enter new passenger name: John

System Menu
=============
1) Find Seat of Passenger
2) Set Passenger at a seat
3) Swap Passenger Seats
4) Print List Of Passengers
5) Exit
2
Enter seat number: 1
Enter new passenger name: Jack

System Menu
=============
1) Find Seat of Passenger
2) Set Passenger at a seat
3) Swap Passenger Seats
4) Print List Of Passengers
5) Exit
4
Seat 2 : John
Seat 1 : Jack

System Menu
=============
1) Find Seat of Passenger
2) Set Passenger at a seat
3) Swap Passenger Seats
4) Print List Of Passengers
5) Exit
3
Give passenger name: John
Give old seat number: 2
Give new seat number: 1
Swapping passengers John (seat 2) Jack (seat 1)

System Menu
=============
1) Find Seat of Passenger
2) Set Passenger at a seat
3) Swap Passenger Seats
4) Print List Of Passengers
5) Exit
4
Seat 2 : Jack
Seat 1 : John

A more detailed example is provided here.

Once the user defines the code of the flight and the number of passengers, the system will repeatedly ask the user to:
Seat 0 is reserved for special purposes, so your program should make sure that no one gets assigned to this seat. The name and seat of each passenger are stored in equivalent places in the two arrays. For example, if for a flight with 10 passengers, only passenger "John" has currently booked seat 3, then in the first element of each of the two arrays you should store the data "John", 3. You should make sure that, as more passengers are added to a flight, their data is stored in consecutive positions in the two arrays. So, if passenger "Mary" subsequently is added at seat 5, then the contents of the two arrays should be {"John", "Mary", ...}, {3, 5, ...}.

Regarding the swapping of seats, as you can see from the example above, the system should ask the user the name of the passenger that wishes to change his seat, his current seat number and the new seat number. If someone else is already seated at that specific place, then we swap the seats of the two passengers. If no one is currently seating at the wanted seat, then the seat just gets assigned to the passenger.
 
You must implement the appropriate checks that relate to the validity of the seat numbers for the first three choices and you must communicate to the main method the fact that the action failed to complete through appropriate return values. You may choose whichever values seem intuitively correct to you -- for example if you can't find a specific passenger in any seat then you may return -1 as the seat number.

We have provided a template template.java with signatures of all the constructors and methods you should define. You will write the remaining code which includes the instance variables and the methods in the Flight class. You can also add any helper methods you need for you implementation. 


Submission and Grading:

Always include your names, slip days, and a comment at the top of your file. Here is the template for Flight.java.

/**
* @author name 1: discussion section time:
* CS account user name:
* Section Unique Number: 
* slip days used on this assignment: ??/4
* total slip days used: ??/6
*
* @author name 2: discussion section time:
* CS account user name:
* Section Unique Number: 
* slip days used on this assignment: ??/4
* total slip days used: ??/6
*
* On our honor, we followed the pair programming rules of splitting
* keyboard time evenly and 80% or more joint development, and we have
* neither read nor copied code, nor have we shown or given our code to
* others.
*
* @version Date
*
* Extra Credit attempted (Yes/No):
*
* Describe what this program does, including any extra credit attempted.
*
*
*/

Submit your version of Flight.java using the turnin program . If you need help goto turnin program help.

Your program should be internally correct (sound logic) and externally correct (following Java style guideline).

If you are submitting without a partner, please include your initial partner and the email correspondence with the instructor or with the TA in your header.