Question: public class DecisionTree extends BinaryTree implements DecisionTreeInterface { private BinaryNode currentNode; / / Tracks where we are in the tree public DecisionTree ( ) {

public class DecisionTree extends BinaryTree implements DecisionTreeInterface
{
private BinaryNode currentNode; // Tracks where we are in the tree
public DecisionTree()
{
/* Add code to here to inherit parent class */
resetCurrentNode();
}// end default constructor
public DecisionTree(T rootData)
{
/* Add code to here to inherit parent class */
resetCurrentNode();
}// end constructor
/* Change the following code for DecisionTree as Binary Tree */
public DecisionTree()
{
/* Add code to here to inherit parent class */
resetCurrentNode();
}// end constructor
public DecisionTree(T rootData, T responseForNo, T responseForYes)
{
/* Change the following code for DecisionTree as BinaryTree responseForNo and responseForYes */
/* Add code */ DecisionTree leftTree
/* Add code */ DecisionTree rightTree
/* Add code */ setTree();
resetCurrentNode();
}// end constructor
public T getCurrentData()
{
if (currentNode != null)
return currentNode.getData();
else
return null;
}// end getCurrentData
public void setCurrentData(T newData)
{
if (currentNode != null)
currentNode.setData(newData);
else
throw new NullPointerException();
}// end setCurrentData
public void setResponses(T responseForNo, T responseForYes)
{
if (currentNode == null)
throw new NullPointerException();
else if (currentNode.hasLeftChild())
{
/* Add code */ BinaryNode leftChild
leftChild.setData(responseForNo);
}
else
{
/* Add code */
/* Add code */
}// end if
if (currentNode.hasRightChild())
{
/* Add code */ BinaryNode rightChild
rightChild.setData(responseForYes);
}
else
{
/* Add code */ BinaryNode newRightChild
currentNode.setRightChild(newRightChild);
}// end if
}// end setResponses
public boolean isAnswer()
{
if (currentNode != null)
return currentNode.isLeaf();
else
return false;
}// end isAnswer
public void advanceToNo()
{
if (currentNode == null)
throw new NullPointerException();
else
currentNode = currentNode.getLeftChild();
}// end advanceToNo
public void advanceToYes()
{
if (currentNode == null)
throw new NullPointerException();
else
currentNode = currentNode.getRightChild();
}// end advanceToYes
public void resetCurrentNode()
{
currentNode = getRootNode();
}// end resetCurrentNode
protected BinaryNode getCurrentNode()
{
return currentNode;
}// end getCurrentNode
}// end DecisionTree

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!