An open API service indexing awesome lists of open source software.

https://github.com/bfontaine/jcalc

toy stack-based calculator
https://github.com/bfontaine/jcalc

experimental gui java

Last synced: over 1 year ago
JSON representation

toy stack-based calculator

Awesome Lists containing this project

README

          

# JCalc

[![Build Status](https://travis-ci.org/bfontaine/JCalc.svg)](https://travis-ci.org/bfontaine/JCalc)

`JCalc` is a toy stack-based calculator written in Java. It was made to learn
the Swing API, not as a real project.

## Build

mvn install

## Run

java -jar target/JCalc-1.0.jar

Or double-click on the jar to open the app.

## Usage

`JCalc` uses a stack, which means you can make complicated operations which
deal with priorities without using parentheses. To add the current value to the
stack, press the “push” button (`<<`). You can now type a new value, and either
push it on the stack or use one of the six simple operations.

An operation pop the top of the stack, applies itself on it and the current
value (in that order), and replace the current value with the result.

You can reset everything at any time with the `R` button.

### Example

We want to compute `(3+5)*(4-2)`. In the following table, the first column shows
the pressed button, the second one shows the resulting value and the last one
the internal stack (top on the right).

| Command | Result | Stack |
|---------|-------:|:------|
| `3` | 3 | - |
| `<<` | - | 3 |
| `5` | 5 | 3 |
| `+` | 8 | - |
| `<<` | - | 8 |
| `4` | 4 | 8 |
| `<<` | - | 8, 4 |
| `2` | 2 | 8, 4 |
| `-` | 2 | 8 |
| `*` | **16** | - |