public class ExpressionTree extends BinaryTree
1: package TreePackage;
2: /**
3: A class that implements an expressioon tree by extending BinaryTree.
4:
5: @author Frank M. Carrano
6: @author Timothy M. Henry
7: @version 4.0
8: */
9: public class ExpressionTree extends BinaryTree<String>
10: implements ExpressionTreeInterface
11: {
12: public ExpressionTree()
13: {
14: } // end default constructor
15:
16: public double evaluate()
17: {
18: return evaluate(getRootNode());
19: } // end evaluate
20:
21: private double evaluate(BinaryNodeInterface<String> rootNode)
22: {
23: double result;
24: if (rootNode == null)
25: result = 0;
26: else if (rootNode.isLeaf())
27: {
28: String variable = rootNode.getData();
29: result = getValueOf(variable);
30: }
31: else
32: {
33: double firstOperand = evaluate(rootNode.getLeftChild());
34: double secondOperand = evaluate(rootNode.getRightChild());
35: String operator = rootNode.getData();
36: result = compute(operator, firstOperand, secondOperand);
37: } // end if
38:
39: return result;
40: } // end evaluate
41:
42: private double getValueOf(String variable)
43: { // Strings allow multicharacter variables
44:
45: double result = 0;
46:
47: // < To be defined. >
48:
49: return result;
50: } // end getValueOf
51:
52: private double compute(String operator, double firstOperand, double secondOperand)
53: {
54: double result = 0;
55:
56: // < To be defined. >
57:
58: return result;
59: } // end compute
60: } // end ExpressionTree