HW7 - Creating a Calculator in Java

This assignment will be to simply create a GUI for, and implement a simple calculator. More than anything else this is an excersize in using the Swing library of Java.

You are to implement a calculator that can perform the following operations:

+, *, /, -, !, and exponentiation ( ^ ).

The calculator is constrained to be a GUI implmentation similar in appearance to the standard windows or xwindows calculator programs. This means that you must have a button for each mathematical operation and single digit number which the user must press to construct a valid number, and a window containing the current answer. You do not need to handle operations which exceed the capacity of an integer (though regardless of whether you do or not, you must display all digits of any number). Optionally, for extra credit, you should check as to whether the operation might cause an overflow.

You will have to handle precedence.

The calculator should, at least, have the following buttons, one for each number that may be used to construct a valid operand, one to present the results of a particular calculation (any unfinished calculations (such as a press of 1 and then multiply and then equals...) should be ignored, a clear button, a button that may be used to construct a positive or negative number, and one button for each operation. If you add functionality, you should include more buttons.

Handing in your solution

Your files should contain everything necessary for the assignment. Do not run the script several times to hand in different portions of the assignment, turn in all files at once, each time.

Please be sure your file loads and runs properly on java as installed on the CS machines. Turn it in by running eg

~bap/bin/handin Calculator.java
on a regular UNM CS machine. Though the above indicates one file, if you implement more than one class, you should place each one in a different file, hand in all of these files.

Due: 3:30pm, Nov 30


Barak Pearlmutter <bap@cs.unm.edu>
Shawn Stoffer <storm@cs.unm.edu>