Program 9 - Writing a Calculator Program using Swing
- due Dec 3, 2004 at 11:59 pm
You will write a program that simulates a calculator. Your calculator
will have the following arithmetic functions - addition, subtraction
and multiplication. It will perform these operations on integers. Your
calculator will have buttons for:
- Digits 0 through 9
- Operations +, -, and x
- = sign
Your calculator should display the result of the calculation when the =
sign is clicked.
The calculator should look like a real calculator. You will be graded
in part on how you lay out the components in your GUI.
Develop your program incrementally. Add all the buttons to your frame,
and your label (or whatever component you are using to display the
result). Then attach Listeners to the buttons and decide how to handle
different events.
Assume that the input is valid and make sure your calculator is
working.
After your calculator is working, then decide how to handle different
errors,
e.g. the user clicks 2 operation buttons in succession. Modify your
program
accordingly, and document how you are handling the error.
You will be graded on your program design as well as the accuracy of
your solution. Submit the file Calc.java by 11:59 on the due date.