This assignment’s objective is to write a console-based Java application with which a travel agent could
present options for travel destinations to a client who wants to redeem his or her accumulated frequent flyer
miles. For the sake of simplicity, we will assume all trips depart from O’Hare International Airport and that
the miles represented are required for a roundtrip ticket.
Depending on the distance, each destination requires a different number of frequent flyer miles to obtain a
roundtrip ticket. Note that, if the client travels during the “off season”, he or she may be able to take
advantage of the “off season” mileage of a destination that requires fewer miles to obtain a roundtrip ticket
to that particular destination.
A list of destination cities and related ticket redemption information will be read from a file (one named
d is provided for you but you may create your own). The file is formatted with one
city, or destination, per line, with the first five items, or fields, separated by a semicolon ( ) and the last
two separated by a hyphen ( ) as shown in the example below. The six items regarding a single destination
The destination city name; the normal mileage needed for an economy class ticket; the “off season”
mileage needed for an economy class ticket; the additional mileage needed for upgrading from economy to
first class; the beginning month of departure during which “off season” mileage can be used instead of the
normal mileage – the ending month of departure during which “off season” mileage can be used instead of
the normal mileage
Example Input File:
The above are the contents of file as attached to the Assignment on Blackboard.
Your algorithm should 1) try to get tickets that travel the farthest, 2) use “off season” mileage whenever
possible, 3) try to display as many different tickets as possible given the information, and, only after you
have determined the destinations to which the customer can fly, 4) determine if you can use the remaining
mileage for upgrade for any of the destinations to which the customer is eligible to fly (try to upgrade the
longest trip first, then the next-to-longest – if there is one, etc.).
CSCI 470/502 Assignment 4 – Java Console Program Page 2 of 6
Write a class that encapsulates information such as the name of the destination city; normal miles required
for a ticket; “off season” miles required to for a ticket during the “off season” months; additional miles for
upgrading from economy to first class; start month of the “off season” and end month of the “off season”.
Private instance variables and public accessor methods should be written for this information.
Write a class to encapsulate the logic for redeeming mileage. This class should have private instance
variables for an array of objects, and an integer to represent the remaining miles after the
user’s Frequent Flyer Miles have been redeemed.
Define the following methods in the class:
For this method, we use a object as the input parameter for flexibility and reusability. For
example, we could reuse the method to read files from different sources. This method should use
the object to read and parse the destination data into an array of objects.
Before ending, the method should sort the array of objects in descending order by normal
mileage (see more information about sorting below).
This method should loop through the array of objects and create an array
of objects from the city names. This array can be sorted in ascending order and returned (to be
printed out by the main program) just for the display of all possible destinations.
For this method, miles is the total available miles, and month is the desired month of departure. To
avoid writing one huge method, you can (and probably should) have the method call
some other methods to accomplish subtasks as part of the larger overall algorithm. This method should
return an array of objects containing descriptions of redeemed tickets to be printed out by the
main program. It should also save the miles remaining after the tickets have been redeemed.
This method should return the saved remaining miles.
This is the main app class that will have the method and will drive the entire process.
First declare a object for the keyboard and prompt the travel agent for the name of the file
of destinations. Next, it should declare another object to read the destination records from the
CSCI 470/502 Assignment 4 – Java Console Program Page 3 of 6
file. This will be the parameter passed to the method of the
class where the array of destinations will be created.
Once back from , use to get and print the list of all possible
destinations. Prompt the travel agent for the client’s Frequent Flyer Miles balance and for the client’s month
of departure. Using these two integers, call to determine the destinations available to
which the client can fly and present them to the travel agent.
Note that, if returns an empty array, print an appropriate message such as:
*** Your client has not accumulated enough Frequent Flyer Miles ***
Either way, then use to present the Frequent Flyer Miles remaining after
determining the destinations to which the client can fly.
After presenting the possible destinations and remaining miles, prompt the travel agent asking if he or she
would like to start over. Do not ask for a new file name, do not print the header statement and do not print
the list of all possible destinations again. Let the travel agent answer with ‘y’ or ‘Y’ or ‘yes’ or ‘Yes’ and, if
he or she answers in the affirmative, the next thing he or she should see is a prompt to enter the client’s
Frequent Flyer Miles and departure month and the process of determining a new list of possible destinations.
Because the cities in the input text file will probably be out of order based on normal miles, the
method will need to sort them in descending normal miles order before any
redemptions can be done. The class has a static method that takes an array
and an implementation of . The latter is an object of a class that defines the ordering:
Note that this class is optional as you may be able to find a different way to implement the Java interface
. For example, create an inner class.
Note: The array of city name strings created and returned by can also be sorted using
a version of . There’s no need to write a in this case, though, as the “natural
ordering” of the strings will be sufficient.
CSCI 470/502 Assignment 4 – Java Console Program Page 4 of 6
Exception Handling and Input Validation
For simplicity’s sake, please do not add try catch blocks for exception handling and do not do any sort of
File I/O and Parsing
The class can be used to read the lines from the file. Before reading the lines, a
should be created:
As lines are read from the input file, the lines need to be parsed, or broken into fields, using “;” as the
delimiter. Instances of are created and added to the array list. There are a variety of
different ways to parse a into fields. One easy way is to use the method of
the class. Note that the last two fields, i.e., begin month and end month for the “Frequent Flyer”
months, are separated by a hyphen.
To change a to an integer to assign to the three miles instance variables and the beginning and
ending month instance variables, use wrapper class ‘s method .
After the whole file is read, the can be converted to a normal, fixed-length array of objects:
By doing this, we can take advantage of Java’s built-in methods for sorting an array.
Reading the File
So that you will not have to do any exception handling, add the following at the end of the method
declaration that reads the input file (no semicolon at the end of it):
Please read the Java Coding and Documentation Guidelines document in Course Documents on
Blackboard before submitting your final program for grading.
Submitting the Assignment
The assignment will be submitted on Blackboard. Please submit the three (or four) .java files on
Blackboard. DO NOT ZIP THEM AND DO NOT SUBMIT THE INPUT FILE!
(Exact output follows)
CSCI 470/502 Assignment 4 – Java Console Program Page 5 of 6
Exact Program Output Using the File Provided
CSCI 470/502 Assignment 4 – Java Console Program Page 6 of 6