Compile Salesperson.java and see what you get.
Just because we say it implements Comparable doesn't make it so! We need to define what it means to compare two Salespersons by writing a compareTo method for the Salesperson class. The comparison should be based on total sales; that is, return a negative number if the executing object has total sales less than the other object and return a positive number if the sales are greater. Use the name of the sales person to break a tie (alphabetical order, last name then first name); if the sales and the names are the same, return 0.
Choose the data for your test case wisely!
Be sure to include data that will verify that your program works in all conditions. Included comments in your program that justifies your data set.
Now you will use this program to examine the runtimes of insertion sort and selection sort. You can do this using the java method long System.currentTimeMillis(), which returns the current system time in milliseconds. (Note that it returns a long, not an int.) In TimeSorts, just get the system time immediately before and immediately after you perform either of the sorts. Then subtract the first from the second, and you have the time required for the operation in milliseconds.
Note that the first couple of times you run a method you might get longer runtimes as it loads the code for that method. Ignore these times and use the "steady-state" times you get on subsequent runs. You will be collecting a series of times on arrays of different sizes to get a sense of how these sorting algorithms work.
Download the file SortingCompare.sxc to your directory. This is an spreadsheet file that can be used with OpenOffice. Go to the Applications menu (on the desktop), select Office -> OpenOffice Spreadsheet. When the application has launched you can open the file using File->open When you open the file, you should see 4 major sections in the spreadsheet:
Complete the "Sort Performance" table by repeatedly running TimeSorts with the appropriate sorting algorithm and arraysize. When the table is complete, you should see a graph of the sort performance in the "Random Array Sorts" chart. Now is a good time to save this file.
Create a new data file called "SortCompare.xxx" where "xxx" are your initials. In this file write an explanation of the sort performance in terms of the algorithm complexity. Discuss how the execution time changes for different array sizes using the same algorithm and how the execution time changes for the same array size using different algorithms. To help with your discussion, it is useful to compare the algorithm's performance against a generic function. To see this visually in the chart, you can copy (one at a time) the comparison functions (n, n^2, and n^3) to the column next to the Sort Performance table (column D). How does the growth of these functions compare to the growth of the algorithm?
Next we want to compare how these algorithms perform on a list that is already sorted (Do you think there will be a difference?) In the spreadsheet, click on the "Sorted Arrays" tab, to get a new sheet that will allow you to record this data. It should look identical to the previous sheet, but without your data.
To fill this out, you will collect data the same way as before, except don't randomize the lists between sorts and don't record the first sort (it will be the time for an unsorted array). When the Sort Performance table is completely filled out, analyze the results and record your findings in "SortCompare.xxx". You should have found a significant difference between the algorithm's performance - justify why this is the case - think carefully about how you should characterize the performance of the insertion sort on a sorted list -- is it constant? Try some timing some array sizes that are very large until you can answer this question.
tar czf lab6.tgz .