Skip to content

A sophisticated calculator application built in Java with a graphical user interface that supports complex mathematical expressions with proper operator precedence and error handling.

Notifications You must be signed in to change notification settings

ialiakbar/java-calculator-gui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Calculator GUI

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.

Features

  • 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

Technical Implementation

  • 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

How to Run

  1. Compile the Java files:

    javac *.java
  2. Run the application:

    java Calculator

Usage

  • 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

Project Structure

  • Calculator.java - Main application class and calculation logic
  • Expression.java - Expression parsing and evaluation engine
  • Frame.java - GUI implementation and user interface
  • UML.pdf - UML diagram of the project architecture

Requirements

  • Java 8 or higher
  • No external dependencies (uses only standard Java libraries)

Error Messages

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

About

A sophisticated calculator application built in Java with a graphical user interface that supports complex mathematical expressions with proper operator precedence and error handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages