If you want to chain methods, then they can't be "void" - in other words, return nothing. They should return the result of the previous calculation - what in the code is stored in "z".
There's no point really in using an interface here. You could use one if all the individual operations (plus, minus, multiply, ...) each had their own class; but that would be a contrived use. [ December 13, 2008: Message edited by: Ulf Dittmer ]
Take a look at java.lang.StringBuilder. After modifying its contents, it returns "this":
Of course you can do the same if you want to keep your contents fixed. In that case, take a look at java.math.BigInteger. A few examples:
Both can now be chained:
The first line creates one single StringBuilder object that has three strings appended to it. The second line creates 5 BigInteger objects: - new BigInteger("5") - new BigInteger("6") - the result of 5 + 6 - new BigInteger("7") - the result of (5 + 6) * 7