This project calculates capital gains tax based on a series of buy and sell operations represented by JSON data.
The program receives lists as input, one per line, of stock market transactions in json format via standard input ( stdin ).
For each input line, the program must return a list containing the tax paid for each operation performed.
An input example can be found at example/input.txt
.
This projects uses the following libraries:
-
jackson-databind: To parses the JSON input string and write the output as JSON.
-
junit-jupiter-api: To create and run unit tests.
-
lombok: Used to reduce boilerplate code. e.g: getters/setters
This project rounds decimals using half up
and 2 decimal places. To implement this, the
BigDecimal java class was used with a predefined
scale of 2 and RoundingMode.HALF_UP
.
- Java 17+
- Maven (https://maven.apache.org/)
make build
Expecting user input:
make run
Using an input.txt
file:
make run < example/input.txt
make test
Build the docker image:
docker build -t capitalgainstax .
Running docker expecting user input:
docker run --rm -i capitalgainstax
Running docker using input.txt
file:
docker run --rm -i capitalgainstax < example/input.txt