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.
ActionListenerinterface. 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.
AddingMachineclass to include all of the fields and methods.
ActionListenerinterface, and add a stub (method with no code between the curly brackets) for the method required by the interface.
Integerobject, rather than as a
Stringof digits, so that the value can be used in arithmetic.
toStringmethod in the Integer class.
Stringthat labels the button by sending the
parseIntmethod to convert a String of digits to an integer.
This will cause an error if the button that was clicked is not labeled with an integer.int digit = Integer.parseInt(e.getActionCommand());
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 your lab instructor. Alternatively, you may submit your class diagram in hardcopy. Use the subject line CIS-180 HW#7 in your email.
Make sure you send your homework to the proper place. Homework sent to the wrong address may not receive credit!
|L1||Mon. 2PM||Wes Fowlksfirstname.lastname@example.org|
|L2||Wed. 9AM||Neelima Motheemail@example.com|
|L3||Wed. 1PM||Wes Fowlksfirstname.lastname@example.org|
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.