|Fifth Assignment: A Binary Tree Editor
Dave Matuszek, Spring 2003
Implement a binary tree ADT. Then (in a separate class) design and implement a binary tree editor.
In this part of the assignment you implement a BinaryTree class. The design (and a lot of the implementation) has been done for you in my Binary Tree ADT lecture; your task is to complete the implementation. Be sure the class is well-commented (with javadoc comments) and bulletproof--that is, there is no way that we can cause your BinaryTree to crash or become invalid. We will try to break your code.
private Object value
private BinaryTree leftChild
private BinaryTree rightChild
private BinaryTree parent
public BinaryTree(Object value,BinaryTree leftChild,BinaryTree rightChild)
public BinaryTree(Object value)-- sets left and right children to null
public BinaryTree()-- sets everything to null
Getters and setters:
public BinaryTree getLeftChild()
public void setLeftChild(BinaryTree child)
public BinaryTree getRightChild()
public void setRightChild(BinaryTree child)
public BinaryTree getParent()
public Object getValue()
public void setValue(Object value)
public boolean isRoot()
public boolean isLeaf()
public BinaryTree detach()
- Note that this is slightly different than the method described in my lecture; it returns a reference to the BinaryTree node that was detached.
public static BinaryTree load(String fileName) throws IOException
public void save(String fileName) throws IOException
public String toString()
public void print()
- You may have additional methods as desired. However, any extra methods should either be declared
privateor they should be general purpose and have a clear reason for being made generally available.
This is the challenging part. Your job is to design and implement a GUI-based editor for BinaryTrees. Your editor must be able to read, edit, and save binary trees.
The value of a node in a BinaryTree may be any kind of Object. Since you cannot easily create arbitrary objects from a GUI interface, you can assume (in your
BinaryTreeEditor) that all values in the
BinaryTreewill be of type
String. You should not assume this in the
A significant part of your grade will be based on how intuitive (easy to figure out) your editor is, and how convenient it is to use for some tasks that we will attempt. One or more of the tasks will be rearranging large parts of the binary tree (for example, take this entire subtree and move it over to here).
Although you cannot share code (all programming must be your own), I strongly encourage you to get together with one or more other students and try out one another's GUIs. This is the simplest and best way to discover what is confusing or hard to use about your interface. Do this as early as possible so that you have time to make any needed changes. You may borrow ideas (but not code) from other people's interfaces.
Optional: Because some binary trees are defined to have values only in their leaves, you could have a setting that will ensure all non-leaf nodes have
nullin their value fields. If you do, be sure that your code is bulletproof and that you don't throw away any values without first checking with the user. This part is optional (for extra credit) because I think it might turn out to be difficult to do in a way that protects the data.
Due date: Thursday, March 20.