Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone help me in figuring out how to set up this Tree.java UML? The othe

ID: 3690260 • Letter: C

Question

Could someone help me in figuring out how to set up this Tree.java UML?
The other Java code I had to do was a BTNode.java, which I got working.

Private Fields
-root: BTNode<E>
-numItems:int
**No-arg constructor that sets root to null/numItems to 0

+Tree()
+add(element:E):void **Don't forget to add 1 to numItems(?) Kind of unsure about that
+size():int
+inOrderPrint():void <- calls root. inOrderPrint() if root is not null
***printTree() [ calls root.inOrderPrint() ]

It also asks me to extend Comparable for the .compareTo() to work
public class Tree<E extends Comparable<E>>

**I'm not sure what that means. Please help if you can!

Explanation / Answer

public class BTNode { protected E element; protected BTNode left, right; // This will creates a new tree node with the specified data and will add the element E. public BTNode (E element) { this.element = element; left = right = null; } // This function will returns the element stored in this node. public E getElementhere() { return element; } // This function sets the element stored in this node. public void setElementhere (E element) { this.element = element; } // This function will return the left subtree of this node. public BTNode getLefthere() { return left; } // This function Sets the left child of this node. public void setLefthere (BTNode left) { this.left = left; } // This function returns the right subtree of this node. public BTNode getRighthere() { return right; } // This function Sets the right child of this node. public void setRighthere (BTNode right) { this.right = right; } // Thid function returns the element in this subtree that matches the specified target. Returns null if the target is not found. //----------------------------------------------------------------- public BTNode search (E targetlement) { BTNode result = null; if (element.equals(targetelement)) result = this; else { if (left != null) result = left.find(target); if (result == null && right != null) result = right.find(target); } return result; } // Returns the number of nodes in this subtree. public static long treeSize(BTNode root) { int result = 1; if (left != null) result += left.count(); if (right != null) result += right.count(); return result; } //This will performs an inorder traversal on this subtree, updating the // specified iterator. public void inordertraversal (ArrayIterator iter) { if (left != null) left.inorder (iter); iter.add (element); if (right != null) right.inorder (iter); } public int height() { int l = 0; int r = 0; if(left != null || right != null) { if(left != null) l = left.height(); if(right != null) r = right.height(); if(l > r) return l + 1; else return r + 1; } else return 0; } }