Homework 08 (Due 11:00am Friday, March 13, 2009)
Submit via Owl-Space
Preliminaries
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 problem HTDP problem 12.4.2 in HW2 as a Java method for aWord
class provided
in the file Word.dj1. This file includes definitions of the composite pattern classes
Word
andWordList
. Decompose the problem in exactly the same form as the posted solution to problem 12.4.2 (see the HW2 entry in the course calendar on the main wiki page). We are providing
skeletons for the classesWord
andWordList
in the file WordList.dj1 (https:wikiriceedudisplayCSWIKI211hw8WordListdj1); use them. -
Write the
mergesort
function from the last problem in HW4 (using exactly the same top-down approach described in HW4) as a Java method in the
composite pattern classComparableList
provided in the file ComparableList.dj1 (https:wikiriceedudisplayCSWIKI211hw8ComparableListdj1). -
Do Exercise 21.2.3 from HTDP using the Java composite pattern class
ObjectList
provided in the file ObjectList.dj1 (https:wikiriceedudisplayCSWIKI211hw8ObjectListdj1). This file includes the interfacePredicate
, which is the type of Java function arguments passed to thefilter
method, and abstract method stubs forfilter
,eliminateExp
,recall
, andselection
. Exercise 21.2.3 provides Scheme code for thefilter
function which you should directly translate to the corresponding Java method code inObjectList
. Note that yourfilter
method should work for arbitraryObjectLists
. In coding the methodseliminateExp
,recall
, andselection
, use the Java typeNumber
(compared using methoddoubleValue=) in place of the Scheme =number
type and
the Java typeObject
in place of the Schemesymbol
type. The methoddoubleValue()
inNumber
returns the value of this converted to adouble
. You will need to cast theObject
input of thetest
method to typeNumber
when filtering lists of numbers. -
Do Problem 2 from Homework 5 in Java using the composite hierarchy of classes provided in the file ArithExpr.dj1 (https:wikiriceedudisplayCSWIKI211hw8ArithExprdj1). (Make sure that download the current version of
ArithExpr.dj1
; an early version declaredEnv
as an interface rather than an abstract class.)