I think you have not understood the principle of this exercise, and the principle of abstract class and polymorphism.
An expression has a calculate() method, which returns the value of this expression. This method should be abstract, because depending on the actual subclass of Expression, the calculate() method won't do the same thing.
Here's an atomic expression: 15. For such an expression, the calculate() method is very easy to implement: it should simply return the value of the number: 15. An AtomicExpression thus has a single field of type double, and its calculate() method simply returns this double value.
A compound expression is a bit more complex: it has two operands (i.e. two fields), of type Expression. The two operands are combined together to calculate the actual value. But CompoundExpression, once again, is an abstract class: the way the two operands are combined depends on the actual subclass.
AdditionExpression is a concrete subclass of CompoundExpression: it takes its two operands, calculates their value (using their calculate() method), and combines them by adding them:
public double calculate() {
return a.calculate() + b.calculate();
}
The SubtractionExpression does the same thing, but with a subtraction instead:
public double calculate() {
return a.calculate() - b.calculate();
}
The goal here is not to make you parse a string. The goal is simply to make you represent an arithmetic expression as an object, using polymorpishm:
(a + b) - (c + d)
is a
Subtraction(a + b, c + d)
which is a
Subtraction(Addition(a, b), Addition(c, d))
which is a
Subtraction(Addition(Atomic(a), Atomic(b)), Addition(Atomic(c), Atomic(d)))