1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| class AddExpression implements Expression { private String variable; private int value;
public AddExpression(String variable, int value) { this.variable = variable; this.value = value; }
public int interpret(Context context) { return context.getValue() + value; } }
class SubtractExpression implements Expression { private String variable; private int value;
public SubtractExpression(String variable, int value) { this.variable = variable; this.value = value; }
public int interpret(Context context) { return context.getValue() - value; } }
|