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.
- Host: GitHub
- URL: https://github.com/khushi130404/postfix-calc
- Owner: Khushi130404
- Created: 2024-01-22T13:48:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-18T03:21:44.000Z (4 months ago)
- Last Synced: 2025-02-18T04:22:23.043Z (4 months ago)
- Topics: infix-to-postfix, postfix-evaluation, precedence, ranking-algorithm, stack
- Language: Java
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.