This is the final version, but still check back for any updates.
A different assignment was briefly listed as hw 6, That assignment
is now hw 7.
Required reading: Savitch text Chapters 1-8. This exercise
should be done using only the material from Chapters 1 through
8.
Due dates: Check the Announcements.
Note you can do this and take an interview without turning in
the assignment, as long as it is before the turnin deadline.
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.
Programming: 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
Hints: You do not need to redefine the methods evaluate or handleDivideByZeroException.
They are inherited from the class calculator and work fine as
is. You probably do want to redefine the methods handleUnknownOpException
and doCalculation.
Last Update: Feb 05, 2003 (by Nakul
Verma)