CIS 180: Object-Oriented Programming
Homework #7

Adding Machine

Due Friday, November 4, 2011

Objectives

The objectives of this homework are:

Problem Statement

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.


Design

Implementation

  1. Add declarations of any additional fields required.
  2. Add the declaration that AddingMachine implements the ActionListener interface, and add a stub (method with no code between the curly brackets) for the method required by the interface.
  3. Add stubs for any addtional methods of your design.
  4. Add code to the constructor method to register as an action listener with each of the buttons.
  5. Add code to change the display when digit buttons are pressed. First, just update the display to show the last digit button pressed (one digit). When that is working, modify your code so that the user can enter multiple digit numbers on the display.
  6. Implement the Clear function of the adding machine.
  7. Implement the Enter function of the adding machine.

Hints

What to turn in

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!

Lab SectionGraderEmail
L1 Mon. 2PM Wes Fowlks u_wfowlks@umassd.edu
L2 Wed. 9AM Neelima Mothe nmothe@umassd.edu
L3 Wed. 1PM Wes Fowlks u_wfowlks@umassd.edu

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.