CIS 636 Spring 2006- Assignment 5 –

Exception Handling, Interfaces, Continuing Combining OOP Pieces in Java 100 points

Assigned: 02/21/2006

Due: 03/14/2006 at the start of class 

You may work individually or in pairs for this assignment. But all work must be the work of the person/people whose name is on the code! If working in pairs, the individual contributions should be relatively equal. One possibility is to work together tonight, then finish separately (to avoid communication difficulties).

Main Assignment:

America East Airline would like more help with running their business.  For this assignment, we will be working with Airports, Routes, and Passengers and collections of them. We are going to add the use of Interfaces and Exception Handling. I have provided a CD with code to be build upon. There is a Collectable and a CollectableWithContainment interface and a MyCollection and MyCollectionWithContainment class. These collection classes hold (as an instance variable) an array of Collectables. We will use these to hold collections of Airports, Routes, and Passengers. I have already made Airport and Route implement Collectable and CollectableWithContainment (Route uses the Containment version because a Route contains Airports). You will need to make your Passenger class implement the appropriate Collectable interface, and also Comparable as well. This includes, adding method(s) necessary for the interfaces. Let’s use frequent flyer points as the determination of which passenger is “larger”.  When finding matches (Collectable) use the customer ID.

The application itself will be an enhancement of assignment 3. It is illustrated in the sample interaction below. After reading in Airports, Routes, and Passengers from files (Collection classes provide a lot of support, but you will need to provide readItemFromFile for the Passenger class), ask the user for which passenger is flying. Allow the user to fly any number of routes they want with that passenger (loop). Make sure that they earn the miles for any acceptable route they fly. After the user quits a chosen passenger, give them a chance to work with other passenger(s) (loop). When they quit the simulation, sort the Passengers by miles earned (see notes below), and display all Passengers in sorted order.

This is also an exercise in Exception Handling. You should use the “robust” methods in RedmondMsgIn instead of using RedmondMsgInBasic (and catch exceptions). These should throw exceptions if the user types letters for numeric inputs (don’t think we have these – Ids are really Strings) or if they hit the cancel button. I believe that the user hitting cancel has given up on that task (e.g. if they cancel when asked for an airport for a passenger, probably they’re giving up on the passenger; if they cancel when asked for a Passenger ID, probably they don’t want to do any more Passengers)

There’s still a lot out there for a realistic application - flights and tickets and boarding passes, and redeeming miles for free travel etc. Don’t worry; I don’t think we’ll end up finishing the whole thing!

Hand in:

You don’t need to print my code, but DO include it in your softcopy!

 

To avoid needless long waits, I recommend working on this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Miscellaneous:

·         I can’t promise you that we will end up finishing this project, because weekly assignments are designed to address specific topics, and the topics needing to be addressed may not fit with what is left to do to create a complete system. However, do your work under the assumption that you will be using it in the future – be robust, document, etc.

·         MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors).  Your program needs to be able to handle any valid inputs, and catch invalid values.  And in reading from the Passenger file, try to signal gracefully if there is a problem.  

·         Put YOUR NAME, and e-mail address and date in comments at the beginning of each file.

·         Also, comment any significant code to document it (each method, each loop, each if, and each significant calculation should have a comment. In particular, each method needs to have a JAVADOC compatible comment).

·         Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceding code (e.g. inside if’s or loops, or statements continued on a new line).  The IDE should handle this if you hit ENTER and move on to the next line (If you make changes, you may need to TAB to make things right).

·         Name your variables meaningfully, to describe their use in the program.

·         The code I gave out on CD for assignment 3 has been updated in a lot of places. Please use the updated version on the new CD. I don’t know that I will get it all out to the WWW site. 

·         For files, I will post a “quick reference” to help. Also, I have included on the CD a class TestDriver2 which basically reads a bunch of files in and writes out to a file what was read in. It does this for a bunch of classes. If I have removed my versions of Pilot, PlaneModel, and Pilot from the CD, you would need to comment out their use in order to get TestDriver2 to run. The key aspects are:

o        Declare collection variables such as,

        MyCollection allAirports = new MyCollection();

        MyCollectionWithContainment allRoutes = new MyCollectionWithContainment(1000);

o         Stick a dummy instance at the front of the array (this is kind of a work around) such as

        allAirports.addNextItem( new Airport());

        allRoutes.addNextItem( new Route());

o        Use the general my collections method to drive reading from the file

            allAirports.readItemsFromFile("airports.txt");

            allRoutes.readItemsFromFile("routes.txt", allAirports);

o        Your class (Passenger) must be able to pull apart a line of text and fill up Passenger info with it. See Route.java for an example.

·         For sorting, my collections class provides a method sortItems(). In order for this to work, your class needs to implement Comparable. This means that you must include a method compareTo which is passed an Object and returns

o        A negative value if the passed object is “less than” the invoking object

o        zero value if the passed object is “equal to” the invoking object

o        A positive value if the passed object is “greater than” the invoking object

Textual Version of Sample Interaction:

What passenger is flying? (by ID#)

82828

Sorry, that passenger number is not found

Do you want to continue with the simulation?

y

What passenger is flying? (by ID#)

44444

Passenger working with: ID: 44444 Name: Darren Daulton Addr: 4 Davidson Dr Denver, CO 70843 Airport: DEN City: Denver State: CO Freq Flyer Type: regular Miles Earned: 0

Now fly around the country and earn frequent flyer miles you earn:

Please enter the starting airport (3 letter code)

POL

Airport POL not found. Please enter the starting airport (3 letter code)

POI

Airport POI not found. Airport POL not found. Please enter the starting airport (3 letter code)

PHL

Please enter the destination airport (3 letter code)

BUFF

Airport BUFF not found. Please enter the destination airport (3 letter code)

BUF

Passenger Status: ID: 44444 Name: Darren Daulton Freq Flyer Type: regular Miles Earned: 380

Do you want to continue with the current passenger?

y

Please enter the starting airport (3 letter code)

PHL

Please enter the destination airport (3 letter code)

SEA

Route from PHL to SEA not found.

Passenger Status: ID: 44444 Name: Darren Daulton Freq Flyer Type: regular Miles Earned: 380

Do you want to continue with the current passenger?

y

Please enter the starting airport (3 letter code)

PHL

Please enter the destination airport (3 letter code)

ALB

Passenger Status: ID: 44444 Name: Darren Daulton Freq Flyer Type: regular Miles Earned: 610

Do you want to continue with the current passenger?

n

Do you want to continue with the simulation?

Y

What passenger is flying? (by ID#)

88888

Passenger working with: ID: 88888 Name: Helene Harrison Addr: 8 Harvest Ct Huntsville, AL 40123 Airport: HSV City: Huntsville State: AL Freq Flyer Type: regular Miles Earned: 0

Now fly around the country and earn frequent flyer miles you earn:

Please enter the starting airport (3 letter code)

ABQ

Please enter the destination airport (3 letter code)

BUF

Passenger Status: ID: 88888 Name: Helene Harrison Freq Flyer Type: regular Miles Earned: 1790

Do you want to continue with the current passenger?

n

Do you want to continue with the simulation?

y

What passenger is flying? (by ID#)

33333

Passenger working with: ID: 33333 Name: Christine Curtis Addr: 3 Clemson Dr Columbia, SC 30321 Airport: CAE City: Columbia State: SC Freq Flyer Type: regular Miles Earned: 0

Now fly around the country and earn frequent flyer miles you earn:

Please enter the starting airport (3 letter code)

LAX

Please enter the destination airport (3 letter code)

BUF

Passenger Status: ID: 33333 Name: Christine Curtis Freq Flyer Type: regular Miles Earned: 2560

Do you want to continue with the current passenger?

n

Do you want to continue with the simulation?

y

What passenger is flying? (by ID#)

55555

Passenger working with: ID: 55555 Name: Ellen Edwards Addr: 5 Evergreen Dr Evansville, IN 50912 Airport: EVV City: Evansville State: IN Freq Flyer Type: regular Miles Earned: 0

Now fly around the country and earn frequent flyer miles you earn:

Please enter the starting airport (3 letter code)

AMA

Please enter the destination airport (3 letter code)

BWI

Passenger Status: ID: 55555 Name: Ellen Edwards Freq Flyer Type: regular Miles Earned: 1620

Do you want to continue with the current passenger?

n

Do you want to continue with the simulation?

n

ID: 33333 Name: Christine Curtis Addr: 3 Clemson Dr Columbia, SC 30321 Airport: CAE City: Columbia State: SC Freq Flyer Type: regular Miles Earned: 2560

ID: 88888 Name: Helene Harrison Addr: 8 Harvest Ct Huntsville, AL 40123 Airport: HSV City: Huntsville State: AL Freq Flyer Type: regular Miles Earned: 1790

ID: 55555 Name: Ellen Edwards Addr: 5 Evergreen Dr Evansville, IN 50912 Airport: EVV City: Evansville State: IN Freq Flyer Type: regular Miles Earned: 1620

ID: 44444 Name: Darren Daulton Addr: 4 Davidson Dr Denver, CO 70843 Airport: DEN City: Denver State: CO Freq Flyer Type: regular Miles Earned: 610

ID: 11111 Name: Abigal Adams Addr: 1 Addison Ave Austin, TX 50543 Airport: AUS City: Austin State: TX Freq Flyer Type: regular Miles Earned: 0

ID: 22222 Name: Bert Bailey Addr: 2 Brentwood Dr Boston, MA 04321 Airport: BOS City: Boston State: MA Freq Flyer Type: regular Miles Earned: 0

ID: 66666 Name: Fiona Franklin Addr: 6 Fairway Dr Fresno, CA 89012 Airport: FAT City: Fresno State: CA Freq Flyer Type: regular Miles Earned: 0

ID: 77777 Name: Greg Grantham Addr: 7 Glanville Pkwy Greensboro, NC 30121 Airport: GSO City: Greensboro State: NC Freq Flyer Type: regular Miles Earned: 0

ID: 99999 Name: Irene Ingram Addr: 9 Inverness Ct Indianapolis, IN 43567 Airport: IND City: Indianapolis State: IN Freq Flyer Type: regular Miles Earned: 0

ID: 00000 Name: Jayson Jackson Addr: 10 Jamestown Ave Jacksonville, FL 39876 Airport: JAX City: Jacksonville State: FL Freq Flyer Type: regular Miles Earned: 0