Lecture 8: Practice Design
Solving a larger problem: practice with wish lists, decomposing problems into subproblems, recursive methods on trees, methods with accumulator parameters
Problem 1
Since you know that wiki articles are not necessarily authoritative sources[citation needed], you want to produce a bibliography containing just the authors and titles of the books you’ve found, either directly or transitively through the bibliographies of other documents. Format the entries as “Last name, First name. "Title".”
Since bibliographies must be alphabetized, sort the bibliography by the authors’ last names.
Documents may be referenced more than once, but should only appear in the bibliography once. Remove any duplicates (defined as the same author name and the same title)
Do Now!
Design your data definitions to represent this information. Design a method to produce a properly formatted bibliography. Design whatever helper methods you need to solve the problem well.
Problem 2
Variant A
A number that is even
A number that is positive and odd
A number between 5 and 10, inclusive
Do Now!
Design a method on lists of integers to check whether the list satisfies these criteria. Hint: what information do you need to propagate down the recursive calls as you process the list?
Variant B
Do Now!
Design a new method on lists of integers to check for this stricter property. How does your design differ from Variant A?
Variant C
Do Now!
Design a third method on lists of integers to check whether the list meets this new property.
Variant Z
Exercise
(Very open-ended) There is something distinctly unsatisfying about designing these solutions to work for precisely three requirements: why not four, or five, or an arbitrary number? Design functions in DrRacket to solve the preceding three problems again, this time supporting an arbitrary number of requirements to be checked on the elements of the list. What essential features of Racket are you using, that we do not yet have in Java?