Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 DecisionTreeT 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 DecisionTreeT 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 setCurrentDataT newData
if currentNode null
currentNode.setDatanewData;
else
throw new NullPointerException;
end setCurrentData
public void setResponsesT responseForNo, T responseForYes
if currentNode null
throw new NullPointerException;
else if currentNodehasLeftChild
Add code BinaryNode leftChild
leftChild.setDataresponseForNo;
else
Add code
Add code
end if
if currentNodehasRightChild
Add code BinaryNode rightChild
rightChild.setDataresponseForYes;
else
Add code BinaryNode newRightChild
currentNode.setRightChildnewRightChild;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started