An open API service indexing awesome lists of open source software.

https://github.com/khushi130404/postfix-calc

Postfix-Calc is an Android application built using Java in Android Studio. It is a calculator that uses Infix to Postfix conversion to evaluate mathematical expressions. The calculator provides a simple and intuitive user interface resembling the iOS calculator.
https://github.com/khushi130404/postfix-calc

infix-to-postfix postfix-evaluation precedence ranking-algorithm stack

Last synced: 4 months ago
JSON representation

Postfix-Calc is an Android application built using Java in Android Studio. It is a calculator that uses Infix to Postfix conversion to evaluate mathematical expressions. The calculator provides a simple and intuitive user interface resembling the iOS calculator.

Awesome Lists containing this project

README

        

# ๐Ÿ“ฑ Postfix-Calc

Postfix-Calc is an Android application built using Java in Android Studio. It is a calculator that uses Infix to Postfix conversion to evaluate mathematical expressions. The calculator provides a simple and intuitive user interface resembling the iOS calculator.

## ๐ŸŽฏ Features

- Converts infix expressions to postfix notation

- Supports the following operations:
- โž• Addition (`+`)
- โž– Subtraction (`-`)
- โœ–๏ธ Multiplication (`ร—`)
- โž— Division (`รท`)
- ๐Ÿ”ข Modulus (`%`)
- ๐Ÿ“ Parentheses (`(` and `)`)
- ๐ŸŸฐ Equals (`=`) to evaluate the expression
- ๐Ÿงน Clear (`AC`) and ๐Ÿ”™ Backspace (`BACK`) operations

- ๐Ÿ“ฑ User-friendly UI designed similar to the iOS calculator

## ๐Ÿ›  Technologies Used

- **Android Studio**: IDE for development

- **Java**: Programming language

- **Stack Data Structure**: Used for infix to postfix conversion

## ๐Ÿ”ข Infix to Postfix Conversion

The conversion follows these precedence rules:
- **Operators Precedence**:
- `+`, `-` have the lowest precedence
- `ร—`, `รท`, `%` have higher precedence
- `(` has the highest precedence for parsing purposes
- Operands are directly added to the postfix expression
- Operators are pushed onto a stack according to precedence
- Parentheses are handled separately for grouping expressions

## ๐Ÿ— Code Structure

The core logic for infix to postfix conversion and evaluation is implemented in:
- **`Infix_To_Postfix1.java`**:
- `infixPrec(char c)`: Determines the precedence of operators in the infix expression.
- `stackPrec(char c)`: Determines the precedence of operators in the stack.
- `rank(char c)`: Returns the rank of an operator to ensure proper expression evaluation.
- `infix_Postfix()`: Converts an infix expression to postfix notation.
- **`Evaluation1.java`**:
- `evaluate(float a, float b, char c)`: Performs arithmetic operations based on the operator.
- `postfixEvaluation()`: Evaluates a postfix expression using a stack.
- `Evaluation1(String ans)`: Initializes the evaluation process by converting infix to postfix.

- **`MainActivity.java`**:
- Handles user input from the calculator UI.
- Listens for button clicks and updates the display accordingly.
- Manages parentheses balancing and ensures valid expressions before evaluation.
- Calls `Evaluation1` to compute the result when `=` is pressed.
- Implements error handling for invalid expressions.

## ๐Ÿ“ฅ Installation & Usage

1. Clone the repository:
```sh
git clone https://github.com/Khushi130404/Postfix-Calc.git
```

2. Open the project in Android Studio.

3. Build and run the application on an Android device or emulator.