Homework Assignment 2

Writing a Simpler Class

CS 2530
Intermediate Computing

Due: Friday, September 14, at 5:00 PM


Note the unusual due date and time.

This assignment asks you to implement an even simpler class than Homework 1. It is part of a larger program, a two-function calculator. You will implement the heart of the program: the object that performs the actual behaviors of the calculator. One new challenge: you will not have a working model on which to base your code.

If you have not done so yet, download the code file for Session 7. This zip file contains a directory with all of the files of the calculator program, in a folder called calculator (surprise).

Among the files you will find there are classes that define the program's graphical user interface, a driver program named TwoFunctionCalculator, and the Accumulator interface. You will write a class that implements this interface and plugs seamlessly into the GUI.

There is no new Java that you need to learn for this assignment. Your focus can be on writing another class and making sure you are following the course coding standards and homework submission requirements.

Designing good methods in Java is similar to designing good functions and procedures in Ada, Python, or any other language. Use helper methods to eliminate duplication and to make code easier to write. Declare any helper methods you write to be private, as they are details of your implementation.

As always, all instance variables are private.

You may do this assignment at the Unix command line or use Dr. Java running on your favorite operating system, whichever you prefer. If you would like some help with Dr. Java, let me know.


  1. Write a class named BasicAccumulator that implements the Accumulator interface.

    Your basic accumulator should implement the behavior observed in Session 7:

    These means that the plus and minus operations are post-fix. For example, if the current total is 42 and the user enters 1 2 -, the new total is 30.

Your class does not need any strings or other data structures to do its job. Java ints are enough.

You do not need to modify any of the existing classes that make up the program, including the AddingFrame that creates and uses a BasicAccumulator. I will test your class with original versions of the other files.

Extra Credit

  1. Write a second Accumulator class that implements infix behavior.

For example, if the current total is 0 and the user enters + 5 4 - 1 2 followed by any operation, the total is 42, and that's what the user sees.


By the due date and time, submit the files

Be sure that your submission follows all homework submission requirements.

Eugene Wallingford ..... wallingf@cs.uni.edu ..... September 14, 2012