Due Date:
Thursday, March 21
File(s) to be submitted:
InsertionSort.java, SortArray.java
Sample Output:
SampleOutput.html
Starter Files:
Summary
Revise InsertionSort and SortArray so that we must provide a Comparator in order to sort the list.
You must not add any methods except
compareTo
in SortArray that takes the Comparator to use.All other modifications must be to existing methods -- adding a Comparator parameter and using it.
Do not use raw generic types. (That is, every Comparator and SortArray must specify the bounds for its base type.)
The classes Person, Student and Undergrad are a small inheritance hierarchy, used to make sure your Comparators have appropriate bounds.
The InsertionSort program I've provided you has been partially revised to sort using a Comparator. The method calls have been changed, but the method definitions have not.
Your task is to change the definitions of the following methods in InsertionSort:
sortNames
sortStudents
insertionSort
You must also add a new method to SortArray:
compareTo
Be sure to give every Comparator an appropriate base type.
In some cases you will need to specify
a restriction on the base type.
See the insertionSort
method
and its restriction on the base type of the SortArray:
It works for String, too,
because String implements Comparable<String>
and as far as super
is concerned,
every class is a supertype of itself.
So you need to think about what kind of a Comparator you need in order to sort a SortArray of base type T.