CPSC 170 Lab 6: More Recursion and Inheritance

As usual, create a lab6 subdirectory for today's lab, open this document in Netscape, and start emacs.

Sierpinski Triangles

A Sierpinski triangle is a geometric figure that may be constructed as follows:
  1. Draw a triangle.
  2. Draw a new triangle by connecting the midpoints of the three sides of your original triangle. This should split your triangle into four smaller triangles, one in the center and three around the outside.
  3. Repeat (2) for each of the outside triangles (not the center one). Each of them will split into four yet smaller triangles. Repeat for each of their outside triangles.. and for each of the new ones.. and so on, forever. Draw a few rounds of this on paper to see how it works, then check out the demo to see it on screen.

Your job is to write an applet that draws a Sierpinski triangle. Think about the following:

When this works (that is, when your triangle looks like the one in the demo), modify it so that when the user clicks a new, random Sierpinski triangle is drawn. (The demo does this too.) This just means choosing three random points and repainting -- nothing will change in your paint or sierpinski methods (if you followed the guidelines above). For fun you can choose a random color each time as well, as the demo does.

Print your Sierpinski program.

Writing a Test

In this exercise you will use inheritance to read, store, and print questions for a test. First, write a class TestQuestion that contains the following: