17.1 The calculator application

The first application to be created is a simple calculator. A JavaBean named CalculatorBean is included to provide the basic mathematical operations on two integer (long) numbers.

This bean has five properties:

Operand 1

Operand 2

Operation

Result

Error message

The bean also has associated getter and setter methods for all of its properties. In addition, the calculate() method calculates the result of one of the following operations:

Add

Subtract

Multiply

Divide

The result is stored in the first number (operand 1) for subsequent operations. If a division does not result in an integer, an exception is thrown. Finally, a toString() method displays the numbers and the operation.


Redbooks
ibm.com/redbooks