CSSE 220 – Object-Oriented Software Development

Homework 12

Objectives

Practice recursion.

Tasks

  1. Complete the assigned reading for the next session, according to the course schedule.
  2. Complete the assessment exercises over this reading on ANGEL (under Lessons → Assignments).
  3. Solo programming: Complete the following exercises from the Recursion project that you checked out in class. Your solutions to all the following must be recursive.
    1. Complete the isPalindrome() and isPalindrome(int first, int last) methods in the Sentence class of the examples package, if you have not already done so.
    2. Implement, including JUnit tests, the reverse() method in the Sentence class.

      How will you compare two Sentences in your unit tests? Suggestion: compare the text strings by using the Sentence class’s toString() method. (Later we’ll see how to define our own equals() method. Feel free to look up how to do that if you’re interested.)

  4. Sierpiński Triangle. This problem is due Tuesday of week 5. However, you should make a strong effort to get started on the problem. If you come to class on Monday having done any parts you find easy, then you can get immediate help on the parts you find hard.

    This problem is in the SierpinskiTriangle project that you should check out from your individual SVN repository.

    Complete the recursive drawSierpinski() method in the SierpinskiRenderer class of the sierpinski package. This method should render the Sierpiński Triangle as shown in the figure below. The triangle is rendered by following these steps:

    1. Draw a solid equilateral triangle (like the big solid red triangle behind all those white ones).
    2. In a contrasting color, draw another solid equilateral triangle whose corner points are the midpoints of the original’s sides (like the medium-sized white triangle pointing down in the middle).
    3. Repeat this process recursively for each of the three corner triangles. That is, you will need three recursive calls in your method.
    4. Technically speaking, this process is repeated an infinite number of times to create the true Sierpiński triangle, but we don’t have that much time. So, stop your recursion when the length of a side of the triangle becomes shorter than some fixed constant, say 5.
    Sierpinski Triangle

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.