Reverse Polish notation (RPN) calculator

In a nutshell RPN allows for compact arithmetic expressions requiring no parentheses to express operator priorities. The introductory article What is Reverse Polish Notation? explains the underlying idea.

This project's comprises two different goals:

  1. Parse and evaluate RPN expressions:

    RPN expression Conventional expression Result Comment
    1 2 + 1 + 2 3
    1 2 3 4 + - + 1 + ( 2 - ( 3 + 4 ) ) -4
    1 2 + 4 * ( 1 + 2 ) × 4 12 No parentheses required
    pi π 3.1415926... symbolic constant pi
    pi sin sin ( π ) 0
    4 sqrt ~ - 4 -2 »~« is Unary minus
    0x1a 0b1101 + 0 3 Binary and Hexadecimal literals
  2. Providing a user interface. Your are expected to write a terminal based application. This leaves different choices:

    The easy way

    Ask the user for line by line input as you already did in e.g. At the bar . This is straightforward but offers little responsiveness.

    The hard way

    Use a library for creating text-based GUIs like Lanterna. This requires some time diving into the API.

    The really hard way

    Depending on your Java skills you may favour a GUI application over the proposed terminal based approach. However do not forget to implement the calculator's logic when fiddling with the user interface and be aware to reserve (possibly a lot of) extra time for the project.

A prototype is available at rpncalculator-0.1.jar. Executing java -jar rpncalculator-0.1.jar allows for evaluating RPN expressions in a terminal: