Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pre-Interview Assignment: Implement a Flexible Calculator

image

Features

  • RESTful APIs CRUD
  • addition, subtraction, multiplication and division
  • Support integers, big integers, floating point numbers, etc.
  • Structured log printing
  • Graceful error handling and clear error messages

Requisites

  • Java
  • Spring 2.x
  • JUnit
  • Log4j2

Get Started

  • The application will start on port 9090

Calculate - Sample Requests

Addition Case 01

curl --location 'localhost:9090/v1/calculator/calculate' \
--header 'Content-Type: application/json' \
--data '{
        "op": "ADD",
        "num1": 1,
        "num2": 2
    }'
{
  "code": "200",
  "message": "Calculation successful",
  "data": 3
}

Addition Case 02

curl --location 'localhost:9090/v1/calculator/calculate' \
--header 'Content-Type: application/json' \
--data '{
        "op": "ADD",
        "num1": 1e308,
        "num2": 1e308
    }'
{
    "code": "400 BAD_REQUEST",
    "message": "Double overflow or invalid result",
    "data": null
}

Chain Calculate - Sample Requests

curl --location 'localhost:9090/v1/calculator/chain' \
--header 'Content-Type: application/json' \
--data '{
    "operations": [
        {
            "op": "ADD",
            "num": 5
        },
        {
            "op": "SUBTRACT",
            "num": 2
        },
        {
            "op": "MULTIPLY",
            "num": 3
        },
        {
            "op": "DIVIDE",
            "num": 4
        }
    ]
}'
{
  "code": "200",
  "message": "Calculation successful",
  "data": 2.25
}

Future Improvements

  • Support for more Operators and Numeric Types. - Expand the calculator to handle more operations (like mod, square root) and support more numeric types (e.g., Long).
  • Add APM, Service Monitoring, and Tracing.
  • Edge case bug fixes
  • Resiliency (Rate Limiting, Retries, Multithreading)

About

No description, website, or topics provided.

Resources

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages