Re: Starting project. Don't know where to start.

Posted 23 October 2012 - 09:32 AM

This was the instructions given to us:
The Triangle Class:
The triangle class encapsulates three Corner objects that define the w and d position of each corner of the triangle that it represents. The Triangle class has a constructor that creates a Triangle object with three Corner objects provided as parameters. This overloaded constructor is provided for you.

The getNextLevel(int index) method calculates the corners of a selected (index) lower level triangle and returns it as a Triangle object. You must write the code for this method to create and return one of the lower level triangles shown in the screen capture based on the index supplied. You must figure out how to calculate the three new corners using the midpoints of the edges of the current triangle. There is a mid method in the Corner class that may be useful. Be sure to generate the corners of each of the new triangles so that it is oriented upside down relative to the current triangle.

The size( ) method calculates the size of the triangle and returns the int value. This value is used in each of your applet classes to determine if the current triangle has gotten too small to continue drawing its sub-triangles. You must write the code for this method also. (Base the size on its geometric perimeter.) There is a len method in the Corner class that may be useful.

The Corner class:
The Corner class encapsulates the w and d pixel values on the screen for one corner of a triangle. As shown in the legend on the screen capture, the w (width) dimension goes left to right and the d (down) dimension goes top to bottom. The code for this class is provided to you.

Iterative Class:
In the iterative version of the Applet, you should instantiate the stack that you need to save the Triangle at each level. You push the initial triangle received as a parameter onto the stack to start the iteration.

Then use a while loop with a condition based on whether there is still another triangle in the stack. In the body of the loop, pop the next triangle off the stack. Process it by drawing it and based on its size determine if you are going to draw its next lower level. If so, get each of the six next lower level triangles from the Triangle getNextLevel(int index) method and push it onto the stack. When the body of the loop stops pushing lower level triangles onto the stack, the while loop will complete the drawing of the triangles down to that level and exit. The Triangle class has a symbolic constant SMALLEST that you can use to terminate drawing before the triangles get too small to see.

Recursive Class:
In the Recursive version of the Applet, you do not need to use an explicit stack. Also, there must be NO iteration statements (while, for, or do … while). You must use selection statements (if – else or switch) and recursive calls only.

The process is similar except that the recursive drawTriangle method calls it self. Process each triangle by drawing it and based on its size determine if you are going to draw its next lower level. If so, call drawTriangle six times – once with each of the next lower level triangles obtained from the Triangle getNextLevel(int index) method. When your code returns from each recursive call to drawTriangle, the context of the previous level of recursion will be automatically restored.

How do I pass screen to the draw method on my triangle?
Correctly check if you are at the Triangle.SMALLEST? That is the smallest you can draw.
How would I then draw the six subtriangles after that check?