Write a program that uses the class Calculator in Listing 9.12 to create a more powerful calculator. This calculator will allow you to save one result in memory and call the result back. The commands the calculator takes are
• e for end
• c for clear; sets result to zero
• m for save in memory; sets memory equal to result
• r for recall memory; displays the value of memory but does not change result. You should define a derived class of the class Calculator that has one more instance variable for the memory, a new main method that runs the improved calculator, a redefinition of the method handleUnknownOpException, and anything else new or redefined that you need. A sample interaction with the user is shown next. Your program need not produce identical output, but it should be similar and just as clear or even clearer.
Calculator on:
```
result = 0.0
+ 4
result + 4.0 = 4.0
updated result = 4.0
/ 2
result / 2.0 = 2.0
updated result = 2.0
m
result saved in memory
c
result = 0.0
+ 99
result + 99.0 = 99.0
updated result = 99.0
/ 3
result / 3.0 = 33.0
updated result = 33.0
r
recalled memory value = 2.0
result = 33.0
+ 2
result + 2.0 = 35.0
updated result = 35.0
e
End of program
```
Create a new class that extends Calculator, add an instance variable for memory, and add the code to implement the new features. Note that you should use the setResult() and resultValue()methods to access the instance variable result from the parent class. There should be a space between the operator and the number. The program does not catch the exceptions that occur when a non-numeric value is entered instead of a number.
See the code in Calculator.java, ImprovedCalculator.java, DivideByZeroException.java, and UnknownOpException.java.
You might also like to view...
How do the wavelengths of visible and infrared light relate to the quality of light transmission signals?
What will be an ideal response?
In contrast to an array, the time it takes to retrieve data from a hash ____ as the hash grows in size.
A. is greater B. is less C. is about the same D. varies back on the type of data stored
The DTD in a Web browser can be as large as necessary.
Answer the following statement true (T) or false (F)
The performance of bubble sort can be improved if we stop the sorting process as soon as we find that, in an iteration, no swapping of elements takes place.
Answer the following statement true (T) or false (F)