CSC 103 Lab Quiz



Instructions

On latte, go to the directory ~gfisher/classes/103/labs/quiz. There you will find a file named ViewableBinaryTree.java. This is a version of BinaryTree with methods that implement the JFC TreeModel interface. There are three additional files in the quiz directory named BinaryTreeNode.java, ViewableBinaryTreeTest1.java, and ViewableBinaryTreeTest2.java. The BinaryTreeNode class is the same one we've been working with in lab. The ViewableBinaryTreeTest1, and 2 classes are testing programs.

To work on the quiz, set things up as follows:

cd ~/csc103
mkdir quiz
cd quiz
cp ~gfisher/classes/103/labs/quiz/*.java .

Your job for the quiz is to implement the five methods of ViewableBinaryTree that contain the comment "FILL IN HERE:". Implement these methods as they are described in the method comments. Here are some important points about the implementation:

  1. You do not need to change any methods other than the five with the "FILL IN HERE" bodies.
  2. The parameters of type Object need to be type cast to BinaryTreeNode within the methods.
  3. Methods that return Object should return BinaryTreeNode values.
  4. Each of the methods except getRoot makes use of BinaryTreeNode to do its work.

Testing

Test that your program works correctly in two phases. First compile and execute as follows:

javac ViewableBinaryTreeTest1.java
java ViewableBinaryTreeTest1
Inspect the output results of this test carefully to see that they are correct. Output lines are of the form:
Test case N, output should be X:

If your program does not produce the "should be" output, then it has a bug that you can pinpoint by looking at which test cases are failing in ViewableBinaryTreeTest1.java.

Once your program runs correctly with ViewableBinaryTreeTest1, compile and execute with test 2 as follows:

javac ViewableBinaryTreeTest2.java
java ViewableBinaryTreeTest2

When the program runs this time, it should display four tree viewing windows. (The windows will probably be stacked up on top of each other in the upper left corner of the screen, so you'll need to move them around to see each of them.) To see all of the tree nodes, click on the little toggle switches next to the nodes so the toggle handle points down. Fully expanded, the tree viewers should look like this:

Full tree

Left-heavy tree

Right-heavy tree

Zig-zag tree

In textbook form the trees look like this:

Turn in

When you have your program working, raise your hand and I'll come around to check it. If you don't get it working by the end of lab, turn in what you have using the turnin program. Turn it in under the assignment name "quiz". Turn in the file ViewableBinaryTree.java.