This project implements a simple calculator in Java that can parse and evaluate mathematical expressions represented as strings. It supports:
- Positive and negative numbers
- Floating-point numbers
- The four basic operations:
+,-,*,/ - Parentheses with proper precedence
- Multiple unary signs (
--,-+, etc.)
All required unit tests (CalculatorTest.java) are fully passing, including the bonus tests for negative numbers and parentheses.
This project uses JDK 17 (LTS).
mvn clean test- Make sure project SDK is set to JDK 17
- Open
CalculatorTestand Run All Tests
javac -d out \
src/main/java/org/isep/cleancode/Main.java \
src/main/java/org/isep/cleancode/calculator/Calculator.javajava -cp out org.isep.cleancode.MainExample:
> --1
= 1.0
> (1 + 2) * 3
= 9.0
> exit
Goodbye!
- Unary operators are handled using a
posiflag to manage sign logic. - Parentheses are parsed recursively.
- The implementation avoids third-party libraries and focuses on clear, readable logic.
- Only standard Java (
java.util) is used.
- Java 17
- JUnit 5
- Maven
- โ Negative numbers supported
- โ Parentheses supported
- โ Public GitHub repo (if you share the link in your email)