|
CS 112 - Introduction to Computer Science II
Final Exam |
Due Date: Thursday 12/13 at 11:30AM.
<superduperimportant>Note: Work is to be done individually
with the only time limitation being the due date. All
file(s) necessary for compilation and execution/testing should be submitted via
Moodle in a .zip file. Submit your work via the Moodle "Final"
dropbox. Please please please please please please please double-check
that you've successfully submitted all necessary file(s). (That is, download
your submission to a separate empty directory, and verify that you can compile and run the Java files.)
Thanks!</superduperimportant>
Final Exam
Note: There are multiple parts to this exam, but all work will be done
stage-by-stage within a single application, including a written question in the
end that will be submitted as a code comment. The separation of the exam
into parts is to encourage good "stepping stones" or milestones for development.
There is no need to maintain separate versions for separate stages.
In this take-home exam, you will be implementing a graphical application to
draw binary fractal trees. Here is a sample screenshot:
1. Recursive Fractal Tree Drawing:
- Create a class FractalTree.java that creates a "Binary Fractal Tree"
JFrame with default exit-on-close behavior, containing a 1000-by-600 pixel
JPanel for recursive fractal line drawing.
- To start with, assume these default parameters for drawing:
- Depth = 10
- Left angle = 30 degrees
- Right angle = 40 degrees
- Left scaling factor = .85
- Right scaling factor = .75
- Root line length = 100 pixels
- Starting at x = 500, y = 500, and angle -90, recursively draw a binary
fractal tree:
- From the root, the line should be the root line length at -90
degrees.
- At the end of each line, the left/right branch will bend to the
left/right and scale in length according to the left/right angle and
left/right scaling factor, respectively.
- From the root to each branch tip, the number of lines to be drawn
will be equal to the depth parameter.
- Chapter 18 of the text on recursion has a similar example that will
be helpful for understanding this recursion.
- The JPanel for drawing should have a white background with black lines.
2. Control Panel:
- At the top of the frame, add a control panel with:
- a "Depth+" button that increases depth and triggers fractal
repainting,
- a "Depth-" button that decreases depth (if above 0) and triggers
fractal repainting,
- a "Depth: " label and text field with the depth that can be edited
directly, or updated via the preceding buttons,
- a "Left Degrees: " label and text field with the angle left branches
bend,
- a "Right Degrees: " label and text field with the angle right
branches bend,
- a "Left Scale: " label and text field with the amount line length is
multiplied when branching left,
- a "Right Scale: " label and text field with the amount line length
is multiplied when branching right,
- a "Length: " label and text field with the root line length, and
- a "Repaint" button that triggers fractal repainting.
- When fractal repainting is triggered by button presses, parameters for
the recursive painting come from the current parameters entered in the text
fields. If there are bad values in the text fields, print an
appropriate simple error message (System.err.println) and do not repaint.
3. Loading/Saving Parameters:
- When the application begins, attempt to read the initial parameters
(e.g. text field entries) from a text file "FractalTreeData.txt". If
that file is not available, use the default values given above.
- Each time the application successfully repainted, save the current
parameters to the text file "FractalTreeData.txt". In this way,
modified parameters should be retained across separate runs of the
application.
4. Big O Time Complexity:
- In a block comment where you perform your recursive fractal painting,
describe your minimum upper-bound for big-O time complexity as depth d
increases. Justify why your bound is correct. (No time data
collection is necessary.)
END OF EXAM