This problem set covers Chapter 11 (Part 2).
Comparable SalesPerson (5 Points)
Add the Comparable interface to the SalesPerson class that you wrote for
Problem Set 8. In Implementing the Comparable interface, you will
implement the compareTo(Object obj) method to compare SalesPerson instances.
For the pursposes of this assignment, your aim is to sort the SalesPerson instances in alphabetical
order.
Your class should still me named SalesPerson and include it in the com.sales package
TreeNode (5 points)
Design and develop a class to represent a binary tree node. This class should have the following private
attributes:
-
nodeObject - A private
Object
instance variable
-
leftChild - A private
TreeNode
instance variable representing the left child of this
node
-
rightChild - A private
TreeNode
instance variable representing the right child of this
node
Your class should have the following public methods and constructors:
-
TreeNode(Object obj) - Initializes the nodeObject to
obj
and sets both
leftChild
and rightChild
to null.
-
get methods for all the private attributes:
-
nodeObject
-
leftChild
-
rightChild
-
set methods for the following private attributes:
Name this class TreeNode and include it in the com.sales package
BinaryTree (10 points)
Design and develop a class that represents a Binary Tree. This class should have the following attributes:
-
root - A private TreeNode inicating the root of the tree
-
sortedObjects - an array of Objects to hold the result of the sort. For the purposes of this
assignment, you can define the length of sortedObjects to be big enough to accommodate your largest
possible SalesForce. In other words, there should be no need to expand this array.
-
currentSortedObject - an int indicating the position in sortedObjects where the
inOrder() method will place the next sorted object.
Your class should have the following public methods and constructors:
-
BinaryTree() - Initializes the following:
-
The root of the tree to null
-
The sortedObjects array to the appropriate size and set all of its entries to
null.
-
the currentSortedObject equals to 0.
-
insert(Comparable<Object> obj) - Inserts obj into the BinaryTree using the code
given in the insert method we covered in class.
-
inOrder() - This method is similar to the inOrder() method we discussed in class. The only
difference is that instead of printing out the contents of the node, in between the two recursive
calls, you add the Object to sortedObjects and increment the currentSortedObject
counter.
-
reset() - This method should reset the sortedObjects array to all null, and the
currentSortedObject to zero.
-
get method for the sortedObjects array.
Name this class BinaryTree and include it in the com.sales package.
Sales Force (1 point)
This is your SalesForce class that you wrote for Problem Set 8.
Modify your displayAllSales() method to sort the sales people in alphabetical order before displaying
the output.