A sophisticated calculator application built in Java with a graphical user interface that supports complex mathematical expressions with proper operator precedence and error handling.
Note: This is a mini project completed for the AP (Advanced Programming) course.
- GUI Interface: Clean and intuitive calculator interface with button layout
- Expression Evaluation: Supports complex mathematical expressions with parentheses
- Operator Precedence: Proper handling of operator precedence using infix to postfix conversion
- High Precision: Uses BigDecimal for accurate decimal calculations
- Error Handling: Comprehensive error handling for:
- Division by zero
- Unbalanced parentheses
- Invalid expression formats
- Real-time Validation: Visual feedback with border color changes for input validation
- Expression Parser: Converts infix notation to postfix for accurate evaluation
- Stack-based Evaluation: Uses stack data structure for expression processing
- Parentheses Balancing: Validates proper bracket matching
- BigDecimal Precision: Ensures accurate decimal arithmetic
-
Compile the Java files:
javac *.java
-
Run the application:
java Calculator
- Use the GUI buttons to input numbers and operators
- Support for basic operations:
+
,-
,*
,/
- Parentheses for grouping:
(2 + 3) * 4
- Clear button (C) to reset
- Plus/minus button (±) for sign changes
- Equals button (=) to evaluate expressions
Calculator.java
- Main application class and calculation logicExpression.java
- Expression parsing and evaluation engineFrame.java
- GUI implementation and user interfaceUML.pdf
- UML diagram of the project architecture
- Java 8 or higher
- No external dependencies (uses only standard Java libraries)
The calculator provides clear error feedback:
- "Brackets are not balanced" - for unmatched parentheses
- "incorrect format!" - for invalid expression syntax
- "Cannot divide by zero!" - for division by zero errors