Skip to content

Reverse polish notation calculator implemented in Java

Notifications You must be signed in to change notification settings

thanus/rpn-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPN calculator

CircleCI Codacy Badge

A command-line reverse polish notation calculator written in Java. The calculator waits for user input and expects to receive strings containing whitespace separated lists of numbers and operators. Numbers are pushed on to the stack. Operators operate on numbers that are on the stack.

Example

The calculator has the following features:

  • Available operators are +, -, *, /, sqrt, undo, clear.
  • If an operator cannot find a sufficient number of parameters on the stack, a warning is displayed: operator <operator> (position: <pos>): insufficient parameters. After displaying the warning, all further processing of the string terminates and the current state of the stack is displayed.

The RPN calculator is built with the following technologies:

  • Java 11
  • Maven

Operations

Operations

  • The ‘clear’ operator removes all items from the stack.
  • The ‘undo’ operator undoes the previous operation. “undo undo” will undo the previous two operations. The memento pattern is used as this lets save and restore the previous state of an object.
  • Sqrt performs a square root on the top item from the stack.
  • The ‘+’, ‘-’, ‘*’, ‘/’ operators perform addition, subtraction, multiplication and division respectively on the top two items from the stack.
  • More operators can be added by simply implementing the Operation class.

Usage

Building from source

After cloning the project, you can build it from source with:

./mvnw clean install

Running commandline

After running the commands below, it will launch the RPN calculator.

java -jar rpn-cli/target/rpn-cli-1.0-SNAPSHOT-jar-with-dependencies.jar

About

Reverse polish notation calculator implemented in Java

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages