©2005 Felleisen, Proulx, et. al.

6  Abstracting with Object, Interfaces, and Function Objects

6.1  Problem

You will start this assignment with the given code. The code defines a list of objects, a class that represents a person, and its derived class that represents a student. There are no examples of data. Some methods are already defined, but do not include tests. By filling in the missing pieces of the design recipe, you will become familiar with the code. You will then add new methods to this class hierarchy.

  1. Draw a class diagram for the given class hierarchy.

  2. Make examples of data as required by the design recipe.

  3. Design and run tests for all methods in the class hierarchy that represents a list of objects, using a list of students as the sample data.

  4. Design the method filter that produces a list of all objects that satisfy the given predicate.

  5. Design an interface ICompare that contains a method betterThan which takes as argument one Object and returns a boolean value.

  6. In the class Person the basis for the betterThan comparison is the alphabetical ordering of the names. In the class Student the ordering is determined by the gpa. Modify each class to implement the ICompare interface accordingly.

  7. Add to the classes that represent a list of Objects the method(s) that implement insertion sort, the ordering determined by the betterThan method of the ICompare interface. Test is with both, lists of Persons and lists of Students.

  8. Design the method that verifies that a list is sorted according to the ordering determined by the betterThan method of the ICompare interface.

  9. Design and implement quicksort for the list of Objects. (Refer to HtDP for the explanation of quicksort.)

6.2  Problem

  1. Define an interface IObj2Obj which contains a method that consumes one Object and produces another Object.

  2. Define a class that implements this interface by consuming an instance of the class Student and producing a String that contains student's id, name, credits, and gpa. For example, it may produce
    "1234, Jenny Smart, 34 credits, gpa 3.4".

  3. Write a test case that produces a list of Strings representing all honors students (with gpa greater than 3.5).

  4. Write a test case that produces a list of Strings that represent all students with more than 80 credits.

Last modified: Friday, February 11th, 2005
HTML conversion by TeX2page 2004-09-11