Note: This is a preliminary version of this exercise.
Problem University keeps records for all students and instructors at the university. For each person it records the name and id number. Each instructor also has a title, and is a member of some department (for now, we just know the name of the department). Each student has a major and grade point average (GPA).
Define the class hierarchy to represent students and instructors at the university, as well as a list of all people, all students, and all instructors.
Define the following methods for these classes:
sortStName
that sorts the students in
a list of Student
s by their name.
sortStGPA
that sorts the students in
a list of Student
s by their GPA.
sortInsName
that sorts the instructors in
a list of Instructor
s by their name.
sortInsDept
that sorts the instructors in
a list of Instructor
s by their department.
Work on refactoring this code as follows:
Study the Java Comparator
interface.
In the class Person
define a Comparator
object that compares the persons by their name.
In the class Student
define a Comparator
object that compares the students by their GPA.
In the class Instructor
define a Comparator
object that compares the persons by their department.
Refactor your code to use a list of Object
s and
rewrite the sort
method so that it receives as
a parameter an object in the class that implements
Comparator
interface.
Add method to find whether an object is in the list.