Description
The following project files must be submitted to the “graded” assignment by the due date and time specified above (see the Lab Guidelines for information on submitting project files). You should plan to start on the project not later than Wednesday in lab. To ensure that your classes and methods are named correctly, you should make sure that your file is successfully submitted to the “ungraded” assignment in Web-CAT during lab on Wednesday. Projects sent via e-mail past the deadline at 11:59 PM will not be accepted without a university-approved excuse.
Files to submit to Web-CAT:
- java
- java
- java
- java
- java
- java
- ItineraryCompare
- AirTicketProcessor
- AirTicketApp
Recommendations
You should create new folder for Project 10 and copy your Project 9 source and test files to it. I recommend that you create a JUnit test file for each class and write one or more test methods to ensure the classes and methods meet the specifications. You should create a jGRASP project and add the class and test files as they are created. You may find it helpful to use the new “viewer canvas” feature in jGRASP 2.0.0 as you develop and debug your program.
Specifications
Overview: Project 10 is the second of three projects that will involve the pricing and reporting of air tickets. In Project 9, you developed Java classes that represent an itinerary and categories of air tickets including non-refundable, economy, business, and elite, all of which include an itinerary. In Project 10, you will modify the AirTicket class and you will create three additional classes: (1) AirTicketProcessor that includes a method to read in a ticket data file and methods to generate several reports, (2) IntineraryCompare which implements the Comparator interface for AirTicket; and (3) AirTicketApp which includes the main method for the program.
• Itinerary, NonRefundable, Economy, Business, and Elite
Requirements and Design: No changes from the specifications in Project 9 |
|
COMP 1210 | Fall 2012 | Page 1 of 6 |
- java
Requirements and Design: In addition to the specifications in Project 9, the AirTicket class should (1) implement the Comparable interface for type AirTicket and do the comparison based on the flight number field; (2) implement the getItinerary() method.
- getItinerary: Accepts no parameters and returns the value for the trip data field of type Itinerary.
- compareTo: Takes an AirTicket as a formal parameter and returns an int indicating the results of comparing tickets based on their respective flight numbers. This method is required for the AirTicket class to implement the Comparable interface for AirTicket.
- java
Requirements: The AirTicketProcessor class provides methods for reading in the data file and generating reports.
Design: The AirTicketProcessor class has fields, a constructor, and methods as outlined below.
- Fields: An ArrayList of AirTicket objects and an ArrayList of String elements to hold invalid records read from the data file. [The second ArrayList will be used in Project 11.]
- Constructor: The constructor has no parameters and initializes the Fields if they were not assigned to ArrayList objects when they were declared.
- Methods: Usually a class provides methods to access and modify each of its instance variables (i.e., getters and setters) along with any other required methods. The methods for AirTicketProcessor are described below. o readAirTicketFile has no return value and accepts the data file name as a String. This method creates a Scanner object to read in the file and then reads it in line by line. I recommend that you set up a second scanner on the line to scan it. For each line scanned, you will create the “appropriate” AirTicket object and adds it to the ArrayList of AirTicket field. The data file is a “comma separated values” file; i.e., the values in each line (or record) are delimited by commas. So when you set up the scanner for the line, you need to set the delimiter to use a “,”. Each line in the file begins with a category for the ticket (N, E, B, and F are valid categories for ticket class indicating NonRefundable, Eeconomy, Business, and First ( or Elite) respectively; note that F (First) will indicate our Elite class. The second field in the record is the flight number, followed by the data for the itinerary (fromCity, toCity, departure Date/Time, Arrival Date/Time, and miles), followed by base price and fare adjustment factor. The last items correspond to the data needed for the particular category of ticket. The file csv is available for download from the course web site. Below are example data records:
B,DL 1865,ATL,LGA,2012/11/01 1400,2012/11/01 1640,800,450,2.0,50.0,50.00
E,DL 1867,ATL,LGA,2012/11/01 1500,2012/11/01 1740,800,450,1.0
F,DL 1863,ATL,LGA,2012/11/01 0900,2012/11/01 1140,800,450,2.5,50.0,50.00,100.00
COMP 1210 | Fall 2012 Page 2 of 6
N,DL 1861,ATL,LGA,2012/11/01 0800,2012/11/01 1040,800,450,0.45,0.90
o generateReport has no return value and processes the AirTicket ArrayList using the original order from the file to produce the Air Ticket Report as shown below in the example output. o generateReportByFlightNum has no return value, sorts the AirTicket ArrayList using the natural ordering, and processes the AirTicket ArrayList to produce the Air Ticket Report (by Flight Number) as shown below in the example output. o generateReportByItinerary has no return value, sorts the AirTicket ArrayList by Itinerary, and processes the AirTicket ArrayList to produce the Air Ticket Report (by Itinerary) as shown below in the example output.
Code and Test: See examples of file reading and sorting (using Collections.sort) in the lecture notes. The natural sorting order for AirTicket objects is determined by the compareTo method from the Comparable interface. If tickets is the variable for the ArrayList of AirTickets, it can be sorted with the following statement.
Collections.sort(tickets);
The sorting order based on itinerary is determined by the ItineraryCompare class which implements the Comparator interface (described below). It can be sorted with the following statement.
Collections.sort(tickets, new ItineraryCompare());
- java
Requirements and Design: The ItineraryCompare class implements the Comparator interface for AirTicket objects. Hence, it implements the method compare(AirTicket t1, AirTicket t2) that defines the ordering from highest to lowest lowest to highest based on the toString() value of each ticket’s Itinerary. Note that the compare method is the only method in the ItineraryCompare class. An instance of this class will be used as one of the parameters when the Collections.sort method is used to sort by “itinerary”. For an example of a class implementing Comparator, see lecture notes 10B Comparing Objects.
- AirTicketApp.java
Requirements and Design: The AirTicketApp class contains the main method for running the program.
Design: The AirTicketApp class has fields, constructor, and methods as outlined below.
- Fields: none
- Constructor:
- Methods: The following method is needed: o main reads in the file name from the user, creates an instance of AirTicketProcessor, and then calls the methods in the AirTicketProcessor class to read in the data file and generate the
three reports as shown in the example output beginning on the next page. An example data file can be downloaded from the Lab web page.
Example Output
ÏÏ«Ï —-jGRASP exec: java AirTicketApp
ÏÏ§Ï ¼¼§ÏEnter File Name: air_ticket_data.csv ÏÏ§Ï Ïϧϗ————————- ÏϧÏAir Ticket Report Ïϧϗ————————- ÏÏ§Ï ÏϧÏFlight: DL 1865 ÏϧÏATL-LGA (2012/11/01 1400 – 2012/11/01 1640) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.0 ÏϧÏTotal Fare: $1,000.00 (class Business) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï ÏϧÏFlight: DL 1867 ÏϧÏATL-LGA (2012/11/01 1500 – 2012/11/01 1740) 800 miles (1200 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 1.0 ÏϧÏTotal Fare: $450.00 (class Economy) ÏÏ§Ï Includes Award Miles Factor: 1.5 ÏÏ§Ï ÏϧÏFlight: DL 1863 ÏϧÏATL-LGA (2012/11/01 0900 – 2012/11/01 1140) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.5 ÏϧÏTotal Fare: $1,325.00 (class Elite) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï Includes: Comm Services: $100.00 ÏÏ§Ï ÏϧÏFlight: DL 1861 ÏϧÏATL-LGA (2012/11/01 0800 – 2012/11/01 1040) 800 miles (800 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 0.45 ÏϧÏTotal Fare: $182.25 (class NonRefundable) ÏÏ§Ï Includes DiscountFactor: 0.9 ÏÏ§Ï ÏϧÏFlight: DL 1866 ÏϧÏLGA-ATL (2012/11/01 1400 – 2012/11/01 1640) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.0 ÏϧÏTotal Fare: $1,000.00 (class Business) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï ÏϧÏFlight: DL 1868 ÏϧÏLGA-ATL (2012/11/01 1500 – 2012/11/01 1740) 800 miles (1200 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 1.0 ÏϧÏTotal Fare: $450.00 (class Economy) ÏÏ§Ï Includes Award Miles Factor: 1.5 ÏÏ§Ï ÏϧÏFlight: DL 1864 ÏϧÏLGA-ATL (2012/11/01 0900 – 2012/11/01 1140) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.5 ÏϧÏTotal Fare: $1,325.00 (class Elite) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï Includes: Comm Services: $100.00 ÏÏ§Ï ÏϧÏFlight: DL 1862 ÏϧÏLGA-ATL (2012/11/01 0800 – 2012/11/01 1040) 800 miles (800 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 0.45 ÏϧÏTotal Fare: $182.25 (class NonRefundable) ÏÏ§Ï Includes DiscountFactor: 0.9 ÏÏ§Ï |
|
COMP 1210 | Fall 2012 | Page 4 of 6 |
Ïϧϗ———————————–
ÏϧÏAir Ticket Report (by Flight Number) Ïϧϗ———————————– ÏÏ§Ï ÏϧÏFlight: DL 1861 ÏϧÏATL-LGA (2012/11/01 0800 – 2012/11/01 1040) 800 miles (800 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 0.45 ÏϧÏTotal Fare: $182.25 (class NonRefundable) ÏÏ§Ï Includes DiscountFactor: 0.9 ÏÏ§Ï ÏϧÏFlight: DL 1862 ÏϧÏLGA-ATL (2012/11/01 0800 – 2012/11/01 1040) 800 miles (800 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 0.45 ÏϧÏTotal Fare: $182.25 (class NonRefundable) ÏÏ§Ï Includes DiscountFactor: 0.9 ÏÏ§Ï ÏϧÏFlight: DL 1863 ÏϧÏATL-LGA (2012/11/01 0900 – 2012/11/01 1140) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.5 ÏϧÏTotal Fare: $1,325.00 (class Elite) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï Includes: Comm Services: $100.00 ÏÏ§Ï ÏϧÏFlight: DL 1864 ÏϧÏLGA-ATL (2012/11/01 0900 – 2012/11/01 1140) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.5 ÏϧÏTotal Fare: $1,325.00 (class Elite) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï Includes: Comm Services: $100.00 ÏÏ§Ï ÏϧÏFlight: DL 1865 ÏϧÏATL-LGA (2012/11/01 1400 – 2012/11/01 1640) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.0 ÏϧÏTotal Fare: $1,000.00 (class Business) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï ÏϧÏFlight: DL 1866 ÏϧÏLGA-ATL (2012/11/01 1400 – 2012/11/01 1640) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.0 ÏϧÏTotal Fare: $1,000.00 (class Business) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï ÏϧÏFlight: DL 1867 ÏϧÏATL-LGA (2012/11/01 1500 – 2012/11/01 1740) 800 miles (1200 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 1.0 ÏϧÏTotal Fare: $450.00 (class Economy) ÏÏ§Ï Includes Award Miles Factor: 1.5 ÏÏ§Ï ÏϧÏFlight: DL 1868 ÏϧÏLGA-ATL (2012/11/01 1500 – 2012/11/01 1740) 800 miles (1200 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 1.0 ÏϧÏTotal Fare: $450.00 (class Economy) ÏÏ§Ï Includes Award Miles Factor: 1.5 ÏÏ§Ï Ïϧϗ———————————– ÏϧÏAir Ticket Report (by Itinerary) Ïϧϗ———————————– ÏÏ§Ï ÏϧÏFlight: DL 1861 ÏϧÏATL-LGA (2012/11/01 0800 – 2012/11/01 1040) 800 miles (800 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 0.45 |
ÏϧÏTotal Fare: $182.25 (class NonRefundable)
ÏÏ§Ï Includes DiscountFactor: 0.9 ÏÏ§Ï ÏϧÏFlight: DL 1863 ÏϧÏATL-LGA (2012/11/01 0900 – 2012/11/01 1140) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.5 ÏϧÏTotal Fare: $1,325.00 (class Elite) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï Includes: Comm Services: $100.00 ÏÏ§Ï ÏϧÏFlight: DL 1865 ÏϧÏATL-LGA (2012/11/01 1400 – 2012/11/01 1640) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.0 ÏϧÏTotal Fare: $1,000.00 (class Business) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï ÏϧÏFlight: DL 1867 ÏϧÏATL-LGA (2012/11/01 1500 – 2012/11/01 1740) 800 miles (1200 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 1.0 ÏϧÏTotal Fare: $450.00 (class Economy) ÏÏ§Ï Includes Award Miles Factor: 1.5 ÏÏ§Ï ÏϧÏFlight: DL 1862 ÏϧÏLGA-ATL (2012/11/01 0800 – 2012/11/01 1040) 800 miles (800 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 0.45 ÏϧÏTotal Fare: $182.25 (class NonRefundable) ÏÏ§Ï Includes DiscountFactor: 0.9 ÏÏ§Ï ÏϧÏFlight: DL 1864 ÏϧÏLGA-ATL (2012/11/01 0900 – 2012/11/01 1140) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.5 ÏϧÏTotal Fare: $1,325.00 (class Elite) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï Includes: Comm Services: $100.00 ÏÏ§Ï ÏϧÏFlight: DL 1866 ÏϧÏLGA-ATL (2012/11/01 1400 – 2012/11/01 1640) 800 miles (1600 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 2.0 ÏϧÏTotal Fare: $1,000.00 (class Business) ÏÏ§Ï Includes Food/Beverage: $50.00 Entertainment: $50.00 ÏÏ§Ï ÏϧÏFlight: DL 1868 ÏϧÏLGA-ATL (2012/11/01 1500 – 2012/11/01 1740) 800 miles (1200 award miles) ÏϧÏBase Fare: $450.00 Fare Adjustment Factor: 1.0 ÏϧÏTotal Fare: $450.00 (class Economy) ÏÏ§Ï Includes Award Miles Factor: 1.5 ÏÏ§Ï ÏÏ©Ï —-jGRASP: operation complete.
|