exerciseExercise[subsection]
[ Exercise Set]©2006 Felleisen, Proulx, et. al.
[©2005 Felleisen, Proulx, et. al.]Exercise Set
Finish all the lab for this week and include it in your portfolio.
Do the first 4 problems below. For the filter method, add
examples of its use in the context of the provided code.
You will start this assignment with the given code. The code as
written runs in ProfessorJ -- separate it into files as needed to
build a Java project. You should also use the TestHarness for
testing of your program.
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.
Draw a class diagram for the given class hierarchy.
Make examples of data as required by the design recipe.
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.
Design the method filter that produces a list of all
objects that satisfy the given predicate.
Design an interface ICompare that contains a method
betterThan which takes as argument one Object and
returns a boolean value.
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.
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.
Design the method that verifies that a list is sorted according
to the ordering determined by the betterThan method of the
ICompare interface.
Design and implement quicksort for the list of
Objects. (Refer to HtDP for the explanation of quicksort.)
Define an interface IObj2Obj which contains a method
obj2obj that consumes one Object and produces another
Object.
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".
Design the method that for the list of Objects that
consumes an instance of a class that implements IObj2Obj
and produces a new list of Objects where every element is
the result of invoking the obj2obj method with the element
of the original list as its argument.
Write a test case that produces a list of Strings
representing all honors students (with gpa greater than
3.5).
Write a test case that produces a list of Strings that
represent all students with more than 80 credits.