Programming Assignment 2

Implement a Reverse Polish notation (RPN) calculator using a stack.

I have provided a skeleton of the edu.gmu.cs.RpnCalculator class which you should complete.

Some basic unit tests are provided to help check your implementation; however, passing these tests does not mean an implementation is correct. There are edge cases not checked by the provided unit tests and this assignment includes requirements not unit-testable.

Table of Contents

Download

The skeleton project may be downloaded here.

Submitting

Submit your RpnCalculator.java source file by midnight on November 15th to avoid a late penalty. Late submissions will lose 10 points per day.

Submissions are accepted over email, please use the subject line INFS 519 Program 2 and send to both myself and the TA.

Requirements

  • Implement all methods in the edu.gmu.calc.RpnCalculator class file.
  • Use a stack to store operands.
  • Subtraction may work on one or two operands, all other operations require two operands. Any operator applied with too few operands should throw an InvalidOperation exception if this condition is not met.
  • Write a main method for your calculator that reads in user input, updates the calculator, and outputs the contents of the operand stack.
    • Users may enter numbers, arithmetic operators, and the letter \q\ (for quitting the program).
  • The operand stack output should include all numbers in the stack on a single line with the bottom value on the left.
  • Produce a working RPN calculator.

Suggestions

  • Write private helper methods to help keep any of your methods from becoming too big or complicated.

Project layout

The project has the following directory layout:

  • RpnCalculator/
    • src/
      • all program source code
    • lib/
      • all project library dependencies
    • test/
      • all test classes

There may also be a separate directory storing your compiled classes.

Building and testing

Use your IDE to build your code and run the included JUnit tests.

Org version 7.7 with Emacs version 23

Validate XHTML 1.0