Project thumbnail

MyCalculator

30 March 2018
A functional calculator implemented from scratch

MyCalculator is a calculator that I built from scratch. It allows addition, subtraction, multiplication, division, use of brackets and percentages (with % symbol), as well as squaring and using square roots.

MyCalculator
MyCalculator supports all most commonly used mathematical operations.

The correctness of the expression is checked while typing; for example, user cannot start an expression with a closing bracket.

MyCalculator – error message
The correctness of the expressions is checked while typing. Here, the user tried to enter a closing bracket after the plus symbol, which is not allowed.

Initially, this project was a practice in using different Java Swing layouts and other GUI elements. Later, I decided to add the expression evaluation and it turned out this part was much more interesting to work on.

When evaluating the expression, the program first generates a corresponding binary tree. The internal nodes of the tree store operations symbols and the external nodes store the numbers. Then the tree is traversed to produce the numeric result of the expression.

MyCalculator – example calculations
A few examples. In the top expression, all supported operations were used.

The calculator, including binary trees and binary tree evaluator, was made entirely without using any external libraries.

You can find the project here.