package jhpro.dtree;
import java.io.Serializable;
/**
* Represents a single node with decision (or answer).
* @author Frans Coenen and Sergei Chekanov
**/
public class BinTree implements Serializable {
public int nodeID;
public String questOrAns = null;
public BinTree yesBranch = null;
public BinTree noBranch = null;
/**
*
* Represents a single node with decision (or answer).
* @param newNodeID node ID
* @param newQuestAnser answer
**/
public BinTree(int newNodeID, String newQuestAns) {
nodeID = newNodeID;
questOrAns = newQuestAns;
}
/**
* Print to the string.
**/
public String toString(){
String ss="";
if (questOrAns != null) ss=questOrAns;
String tmp=Integer.toString(nodeID)+ " "+questOrAns;
if (yesBranch == null && noBranch==null){
tmp="Answer="+Integer.toString(nodeID)+ " "+questOrAns;
}
return tmp;
}
/**
* Get the answer.
* If tree is not ready, it returns -1.
* @return -1 if tree not ready, or node ID if tree is ready for answer.
*
**/
public int getNodeAnswer(){
if (noBranch == null && yesBranch==null) return nodeID;
return -1;
}
}
Ads help maintain this website.