Expression Implementation (Version 2) public class Expression2 { public static final int CONSTANT = 1; public static final int ADDITION = 2; public static final int MULTIPLICATION = 3; public static final int NEGATION = 4; /** Which type is this one? */ private int type; /** The value, if it's a constant */ private int constantValue = 0; /** Left and right sub-expressions, if any */ private Expression2 left = null; private Expression2 right = null; /** Intialise as a constant expression */ public Expression2(int v) { type = CONSTANT; constantValue = v; } /** Initialise as a sum or product */ public Expression2(Expression2 l, Expression2 r, int t) { assert t == ADDITION || t == MULTIPLICATION type = t; left = l; right = r; } /** Initialise as a negation */ public Expression2(Expression2 e, int t) { assert t == NEGATION type = NEGATION; left = e; } ... } Using Expression2 Expression2 a, b, c, d, e; a = new Expression2(1); b = new Expression2(2); c = new Expression2(a, b, Expression2.ADDITION); a = new Expression2(3); b = new Expression2(4); d = new Expression2(a, b, Expression2.ADDITION); e = new Expression2(c, d, Expression2.MULTIPLICATION); System.out.println(e.toString() + " = " + e.value()); Further work for the Software Construction student 1.make it into a program 2.replace all of these constants and relevant int variables and arguments public static final int CONSTANT = 1; etc. with the use of a well-named Java enum type. 3.(preferably using eclipse) refactor: rename Expression2 as Expression 4.fill in all of the dots ( ... ) and more examples, to test your program. Expression Implementation (Version 3) public interface Expression3 { /** The value of this expression */ public int getValue(); /** Pretty infix string representation */ public String toString(); } public class Constant3 implements Expression3 { /** The value */ private int value; /** Initialise value */ public Constant3(int v) { value = v; } /** The value of this expression */ public int getValue() { return value; } /** Pretty infix string representation */ public String toString() { return "" + value; } } public class Negation3 implements Expression3 {... } public class Addition3 implements Expression3 { /** The sub-expressions being added */ private Expression3 left, right; /** Initialise left and right sub-expressions */ public Addition3(Expression3 l, Expression3 r) { left = l; right = r; } /** The value of this expression */ public int getValue() { return left.getValue() + right.getValue(); } /** Pretty infix string representation */ public String toString() { return "(" + left.toString() + " + " + right.toString() + ")"; } } public class Multiplication3 implements Expression3{ ...} Using Expression3 Expression3 a, b, c, d, e; a = new Constant3(1); b = new Constant3(2); c = new Addition3(a, b); a = new Constant3(3); b = new Constant3(4); d = new Addition3(a, b); e = new Multiplication3(c, d); System.out.println(e.toString() + " = " + e.getValue())