For this project you are asked to complete the design and implementation of the AddingMachine class. You will be adding code to the homework from last week to make the adding machine's buttons functional. The adding machine is like a calculator application, but only does addition. The adding machine should function as follows:
Initially the number 0 is displayed. The display is updated as the user presses digit buttons to enter numbers. When the enter button is pressed, the number on the display is added to the previous sum, and the result is displayed. If the enter button is pressed two or more times in a row, only the first press will have any effect. Pressing the clear button resets the adding machine to its initial state.
Click the button below to run a sample solution that demonstrates how the adding machine should work.
ActionListener interface. What method is required by
that interface? Can you use additional methods to further decompose and
simplify the problem? Hint: There are three types of buttons
that can be clicked -- digits, enter, and clear. You might write a method
to handle each of these types of button clicks.AddingMachine
class to include all of the fields and methods. AddingMachine implements
the ActionListener interface, and add a stub (method with
no code between the curly brackets) for the
method required by the interface.Integer rather than as a String
of digits, so that the value can be used in arithmetic.toString message.
String that labels the button by sending the
ActionEvent a getActionCommand message.Integer class parseInt method
to convert a String of digits to an integer. int digit = Integer.parseInt(e.getActionCommand());
This will cause an error if the button that was clicked is not labeled with an integer.When your assignment is complete, add some comments to the comment block of the java source code explaining any problems you encountered in completing the assignment and describing any bugs in your solution.
Submit your source code (AddingMachine.java) as well as your class diagram as email attachments to: ttao@umassd.edu. Alternatively, you may submit your class diagram in hardcopy.Use the subject line CIS-180 HW#7 in your email.
There will be a 10% penalty for assignments received after the due date. Assignments will not be accepted more than one week past the due date.