Computer Science 241
Tree Assignment
Due: December 4, 2002

In this group assignment, put the data for the clown project into a tree.  Use data that you haven’t had in a program before.  Your tree class should implement the tree interface given in class.

This time use the Node class, also given in the tree handout.  Your clown, donor, or facility class should extend it.  Use ‘super’ in the constructor, the read method and the display method.  However, you should change the read and display methods so that they read from a file and display the data in either TextFields or a TextArea.  (See below.)

As the above indicates, you should use a frame for this assignment.  You should be able to add, find and display.  Since deletion from a tree is tricky, either leave it out or mark the node in some way for deletion.  This can be done using a separate boolean variable or a special id.  The boolean variable method is probably easiest.

As in a previous assignment, also hand in a document that explains the decisions you made and how you divided up the work.  Use a word processor such as Microsoft Word.

package tree;
// An interface containing the public methods in the tree class.
public interface TreeInterface
{
     public void addNode (TreeNode newNode);
     public void traverseTree ();
     public boolean findId (String keyId);
} // TreeInterface

/* The Node class defines a node with three fields, one for an id and the other two for references to the left and right nodes in the tree. */
package tree;
import java.io.*;
public class TreeNode
{
     protected String id, name;
     private TreeNode left, right;

     protected TreeNode getLeft (){return left;}
     protected TreeNode getRight (){return right;}
     protected void setLeft (TreeNode left){this.left = left;}
     protected void setRight (TreeNode right){this.right = right;}
     protected String getId (){return id;}
     protected void setId (String id){this.id = id;}
 
     // A method that reads the data for the node from a BufferedReader
     public void readTreeNode (BufferedReader infile, String id) throws IOException
     {
          this.id = id;
          name = infile.readLine ();
     }

     // A method that displays the data in a node.
     public void displayTreeNode (TextArea area)
     {
          area.append ("ID: " + id + '\n');
          area.append ("Name: " + name + '\n');
     }
} //  class TreeNode