A console-based calculator that saves and loads operations using MongoDB. Supports addition, subtraction, multiplication, and division, with persistent storage for previously run operations.
- Run calculations directly in the console (CLI).
- Supports
+,-,*,/. - Each operation is stored as a MongoDB document.
- Load and re-run previous operations from the database.
- Simple, lightweight code structure.
- Java 17+
- MongoDB (as storage backend)
- Lombok (for boilerplate reduction)
- BSON (MongoDB document format)
me.wabuein.calc
βββ operation
βββ Operation.java # Represents a calculation, can be saved/loaded
βββ OperationType.java # Enum: ADD, SUBTRACT, MULTIPLY, DIVIDE
βββ OperationStage.java # Enum for input stages (A, B, Operation type)
- Operation β Holds operands (
a,b), operation type, and can convert to/from MongoDBDocument. - OperationType β Enum of supported operations.
- OperationStage β Guides user input stages (setting first number, second number, operation).
-
Clone the repository:
git clone https://github.com/<your-username>/<repo-name>.git cd <repo-name>
-
Ensure you have MongoDB running locally (
mongodb://localhost:27017by default). -
Build & run the project:
./mvnw clean install java -jar target/mongo-calculator.jar
-
Follow console prompts to:
- Enter number A
- Enter number B
- Choose an operation type
-
The result is printed and saved to MongoDB.
Each operation is stored like this:
{
"a": 10,
"b": 5,
"type": "ADD"
}mongo:
uri-mode: false
normal:
host: 127.0.0.1
port: 27017
auth:
enabled: false
username: ''
password: ''
uri:
database: Calculator
connection-string: mongodb://127.0.0.1:27017/Calculator
MIT β feel free to use and adapt.