Try out my calculator implementation :-)
Unfortunately, the applet will probably not run for you unless you have
Sun's JVM installed, but the source code will still be useful to Java
enthusiasts and fellow computing students.
You get to see some (crude) expression parsing, a stack implementation,
stack unwinding and usage of the Reflection API.
The calculator supports 5 operators : addition '+', subtraction '-',
multiplication '*', division '/' and modulo '%'. Furthermore, it also
supports embedded calls to methods of the Java Math class. The syntax for
an example expression is shown below :
8 * 4 - Math.pow(3,4) / 2.5
In this case, Math.pow(3,4) evaluates to "3 to the power of
4". Other methods which could be used are sqrt and exp, which both
take a single operand.
Spaces between the operands and operators are not required. They are
included in the above expression to improve clarity.
Although everything was designed so that support for nested expressions
could eventually be introduced, this has not yet been done.
Source code and documentation in
jdoc format (zip, 81K)