CSE 8B Spring 2001
Homework #3
Required reading: Savitch text Chapters 8
Turn in due date: Wednesday,
April 25 (i.e., 8 am April 26)
Interview due date: Monday, April 30
DO NOT turnin hw3 before April 20. You can do hw3 before then and even
take an interview, just do not turn it in before April 20.
Note: Do not turn
it in before April 20. you can do it before then and even take an interview
before then, but do not turn it in before April 20.
Programming: You may work in teams of two students, but once you form a team, you cannot change the team for this assignment. You may work alone if you prefer.
This is Programming Project 2 of Chapter 8, which we reproduce below along with details about what to turnin in this class.
Write a program that uses the class Calculator in Display 8.11 to create a more powerful calculator. This calculator will allow you to save one result in memory and call the result back.
Commands are:
-e for end
-c for clear, sets result to 0
-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, a redefinition of the method handleUnknownOpException, a main method that runs the improved calculator, and anything else new or redefined that you need. What a sample dialog should look like is shown in what follows. Your program need not produce an identical dialog, but it should be similar and just as nice or nicer.
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
memory recall
memory value = 2.0
result = 33.0
+2
result + 2.0 = 35.0
updated result = 35.0
e
End of Program
Turn-in Details:
Call your class MemoryCalculator. You turn in only your calculator program which
is the file MemoryCalculator.java that is a derived class of Calculator in Display
8.11. You do not directly use the main method in the Calculator class, but your
class will have a similar main method. You will use the class UnknownOpException
from in Display 8.9. You do not turn in either of the classes Calculator or
UnknownOpException. We will have our own copies to test your program. You are
not allowed to change either of the classes Calculator or UnknownOpException