加算演算子を定義してみます。数値ノードを子にもち、足し算した結果を返します。
加算演算子を定義してみます。数値ノードを子にもち、足し算した結果を返します。
/*** 加算演算子です。*/public class Add implements Node {private Numeric left;private Numeric right;public Add(Numeric left, Numeric right) {this.left = left;this.right = right;}@Overridepublic Node evaluation() {double result = left.getValue() + right.getValue();return new Numeric(result);}}