107 F '08
The Recipes
The Style
The Universe
The World
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11

Problem Set 9


Due date: 11/20


The goal of this problem set is to design classes and methods in an object-oriented language. The design involves structural and generative recursion, plus accumulators


HtDC: 10.1, 10.9, 11.1, 14.2, 14.3, 14.4, 14.5, 15.7, 15.11; also solve the problems from the case-study sections 6.2 and 16.3 so that you know how to design draw methods in this Java-like language.

Required Problems:

Note: You must use the ProfessorJ Intermediate language level for all problems.

  1. Design the method render for your data representation of Enums from problem 8.2. Since ProfessorJ/Intermediate (nor Java) doesn't include images as first-class values, the method must render the image onto a canvas and at a specified position. This implies that the method has the following signature:
    boolean render(Canvas c, Posn p)
    Your Example class should create a canvas and a position to render your sample enumerations.

    A second consequence is that you cannot actually test your method. The best you can do is invoke render on examples and inspect the canvas with your eyes.

    As for problem 7.1, the anchor for items in unordered (UL) lists must depend on their nesting depth. For the outermost unordered list use a (blue) disk, next a (red) circle, a (green) square, and from then on (yellow) squares:

    java rendering of enums
    For my solution, I used 2 pixels for the radius for disks/bullets and for the length of the side of squares. As this figure suggests, it is impossible to be faithful to the renderings of the solution to 7.1. Thus you have some freedom with the spacing of items etc. but your renderings must be recognizable.

  2. Design a class-based representation of mobiles, as presented in problem 3.1. Then design the method isBalanced, which determines whether a mobile is balanced. You may find it instructive to solve this exercise in full Java using arrays or vector lists for the representation of beams.

  3. Design a class-based representation of BERs, as presented in problem 5.1. Then design the method evaluator, which determines the Boolean value of a BER. Note that this problem solves on the first part of problem 5.1 and does not mention fevaluate.

    Recall that evaluator in problem 5.1 produced either a boolean or a symbol. In a typed programming language, such as ProfessorJ/Intermediate (or Java), doing so is impossible. Instead, your evaluator function will produce String:

    • "true" if the result is true;
    • "false" if the result is false; and
    • "*error*" if the expression contains a variable (symbol).
    Also, ProfessorJ/Intermediate (or Java) doesn't support symbols; use String instead.

last updated on Tue Jun 9 22:21:18 EDT 2009generated with PLT Scheme