A state object represents the memory of the calculator. You may think of it as representing the printed circuit in the calculator. Its purpose is to keep track of the current state of the computation. For instance, it might keep track of whether the user is entering a number, and what the number is so far. It also might keep track of the stack used in the computation and update the display window.
Objects of class DigitButtonListener and OpButtonListener respond to events generated by buttons which represent digits and operations, respectively. Each digit key has its own specialized DigitButtonListener which is responsible for knowing which number key it is listening to. Similarly each of the operation keys has its own specialized OpButtonListener which is responsible for knowing which operation key it is listening to. When the user clicks on a button with a digit on it, its corresponding listener is responsible for informing the state what number has been clicked, so the state can use it to build the number being typed in. When the user clicks on an operation button (+, -, *, or /), the corresponding listener is responsible for informing the state what operation is to be performed next so that the state can perform the operation.
Notice that we only create special listeners for digits and operations. This is because there are several buttons of each kind. The "unique" buttons: Enter, pop, and clear, are handled directly by the MiscButtonListener. They simply send a message to the state corresponding to the operation.
You might find it easier to write the code first under the assumption that the user must push the "enter" button after punching in each number. However, for full credit, it should also handle the case where the user punches in a number followed immediately by an operation. The result should be equivalent to sticking in an intervening "enter". That is punching in 5, enter, 7, + should give the same results as 5, enter, 7, enter, +.
Once you have the rest of the calculator working properly I would like you to add one or more new buttons. Possibilities include a squaring button, factorial, or xy. You should add the new button so that it looks nice, add an appropriate listener (probably created from OpButtonListener), and make sure that the state knows how to handle that operation.
If you are interested in extra credit, I suggest that you add a decimal point button so that your calculator can handle floating point numbers. Be sure to check that the user does not input an illegal number (e.g., with two decimal points). Possibilities for new buttons with this include square root, trig functions (e.g., sin, cos, tan, etc.), inverse trig functions, xy, e x, factorial, inverses, or logarithms. See the class Math in package java.lang for a list of available mathematical functions in Java.
Your final program will be due on Sunday, April 9 at 11:59 pm. Please note that this is the due date for students in the Thursday lab as well as the Wednesday labs.
Place all of your code in a folder and drop it off in the CSCI 136 drop-off folder. Your project should include the four classes specified above: