Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions