Homework 08 (Due 10:00am Friday, March 19, 2010)
Submit via Owl-Space
This homework on manipulating Java lists must be done using the Intermediate language level of DrJava. We are providing skeleton classes for each problem with unimplemented methods for you to write. Each such class includes a method with a name like
listString() that converts lists to more readable String notation similar to that used in Scheme.
Composite Design Pattern for List
- Write the
arrangements(permutations) function from HTDP problem 12.4.2 in HW2 as a Java method for a
Wordclass provided in the file
Word.dj1. This file includes definitions of the composite pattern classes
WordList. Decompose the problem in exactly the same form as this solution to problem 12.4.2. We are providing skeletons for the classes
WordListin the file WordList.dj1; use them.
- Write the
mergesortfunction from the last problem in HW4 (using exactly the same top-down approach described in HW4) as a Java method in the composite pattern class
ComparableListprovided in the file ComparableList.dj1.
- Do Exercise 21.2.3 from HTDP using the Java composite pattern class
ObjectListprovided in the file ObjectList.dj1. This file includes the interface
Predicate, which is the type of Java function arguments passed to the
filtermethod, and abstract method stubs for
selection. Exercise 21.2.3 provides Scheme code for the
filterfunction which you should directly translate to the corresponding Java method code in
ObjectList. Note that your
filtermethod should work for arbitrary
ObjectLists. In coding the methods
selection, use the Java type
Number(compared using method
doubleValuein place of the Scheme
numbertype and the Java type
Objectin place of the Scheme
symboltype. The method
Numberreturns the value of this converted to a
double. You will need to cast the
Objectinput of the
testmethod to type
Numberwhen filtering lists of numbers.
- Do Problem 2 from Homework 5 in Java using the composite hierarchy of classes provided in the file ArithExpr.dj1.