Self-Test 6

Wed, Dec. 1 2010

Exercise:



Today we will create a class called Calculator that can add, subtract, multiply, and divide, as well as keep track of the accumulated results of calculations.





Before you start:
Find a calculator on your system and run it. Do the following calculations:

5 + 4 =
9
6 + 2 =
8  (previous result (9) is lost)
10 + 7 =
17 (previous result (8) is lost)
+ 3 =
20 (3 added to previous result)
* 4 =
80 (previous result multiplied by 4)
/ 8 =
10 (previous result divided by 8)
3 + 5 =
8 (previous result lost)

Your Calculator class should include the following methods:
Write a demo program for light testing.
Write junit tests for more thorough testing.

Note that java can now handle division by 0 - you get Infinity insead of an error...