A business has been collecting and archiving a list of receipt numbers attached to customer numbers and the amount that was spent in the transaction. Up until now this list has not been utilised by the business and is rarely queried. However, they would like to start making use of the data but it is not currently in a usable state.
They require the list of transactions sorted by receipt number and customer number. As with any business they would like the most efficient solution possible so you are required to explore a number of sorting algorithms and compare them all to show which of the algorithms you find to be the best solution. Some properties of the source data that you should factor into your choice of algorithm are that the receipt numbers are semi sorted but the customer numbers are completely random. In addition to this, the receipt numbers are unique but the customer numbers will obviously repeat.
Task 1
First you will need to create a driver class that will read in a specified source file then provide options for how this data is to be sorted. This file is to be named ReceiptSorter.
The first option provided to the user should be a prompt that asks for an input file name.
You will need to load the input file into a list or structure of objects. The source file will be structured with exactly one record per line. Each line will contain 3 comma separated values; receipt number, customer number, then amount spent. E.g.,
17430175,9584150,$101.95
17430180,5522194,$243.20
17430181,9584150,$40.70
17430183,6664946,$31.70
...
This object should have a constructor that takes a single string and splits it into receipt number, customer number, and amount spent. It will also need to implement the interface Comparable and hence have a CompareTo function. Hint: you will find if you follow this correctly, that you will be able to utilize much of the code from Labs.
The driver class should provide menu that initially gives a choice of 1 or 2 as follows. Option 1 to sort by receipt number and option 2 to sort by customer number (option 2 should only be able to be run after sorting by receipt number is performed at least once). Once a selection has been made to sort by receipt numbers or customer IDs then the user should be presented with 4 choices of algorithm.
Once selected the user should be prompted to enter an output file name. Once the sort is complete the program should output the number of lines of data processed, the time taken to run, and the number of comparisons.
1. Sort by receipt number and output to a text file
1. Sorting algorithm 1
* Please enter an output file name and press enter:
2. Sorting algorithm 2
* Please enter an output file name and press enter:
3. Sorting algorithm 3
* Please enter an output file name and press enter:
4. Sorting algorithm 4*
* Please enter an output file name and press enter:
2. Sort by customer number while maintaining receipt number order and output to a text file
1. Sorting algorithm 1
* Please enter an output file name and press enter:
2. Sorting algorithm 2
* Please enter an output file name and press enter:
3. Sorting algorithm 3
* Please enter an output file name and press enter:
4. Sorting algorithm 4*
* Please enter an output file name and press enter:
Algorithms 1 to 3 can make use of only 2 generic containers, Arraylist and/or Vector, or a data structure of your own, such as a tree. No other inbuilt data structures are to be used and the sorting algorithm must be programmed by you.
*Algorithm 4 should use Clollections.sort(list< T>). Bearing in mind that your objects in the list must extend Comparable and contain a CompareTo functions for this to compile and work.
Task 2
Create a short report that includes answers to: