CSSE 220 – Object-Oriented Software Development

Homework 13

Objectives

Practice Recursion.

Tasks

  1. Complete the assigned reading for today's session (Big Java, §13.3–13.5 and §14.1–14.3), according to the course schedule.
  2.  
  3. Complete the assessment exercises over this reading on ANGEL (under Lessons → Assignments).
  4. More Solo programming: Complete the following exercises from the Recursion2 project that you checked out in class. Your solutions to all the following must be recursive or mutually recursive.
    1. Complete the f(int n) and m(int n) methods in the HofstadterFM class of the example package, if you have not already done so.
    2. Complete the recursive drawSierpinski() method in the CarpetRenderer class of the carpet package. This method should render the Sierpiński Carpet as shown in the figure below. The carpet is rendered by following these steps:

      1. Draw a solid rectangle (like the big solid red rectangle behind all those white ones).
      2. Divide the rectangle into 9 congruent subrectangles in a 3-by-3 grid.
      3. In a contrasting color, draw the central solid subrectangle (like the white subrectangle in the middle).
      4. Repeat this process recursively for each of the eight remaining subrectangles. HINT: You might want to use loops to do the recursive call(s) in your method (except, you should not do the recursive call for the center subrectangle).
      5. Technically speaking, this process is repeated an infinite number of times to create the true Sierpiński carpet, but we don’t have that much time. So, stop your recursion when the length of a side of the rectangle becomes shorter than some fixed constant, say 3.0.
      Sierpinski Carpet

Remember, in all your code:

Here is the grading rubric for this assignment.

Turn-in Instructions

Turn in your programming work by committing it to your SVN repository.