Project Repport .here.
This project implements an arithmetic calculator capable of parsing and evaluating mathematical expressions using a custom stack data structure. The calculator handles various arithmetic operations and parentheses, providing accurate results for complex expressions.
- Custom Stack Implementation: A stack with expandable arrays that supports dynamic resizing.
- Expression Evaluation: Converts infix expressions to postfix notation and evaluates them.
- Operator Support: Handles arithmetic operators, power functions, and comparison operators.
- File Handling: Reads expressions from an input file and writes results to an output file.
- Java Development Kit (JDK) 8 or higher
- Java IDE (e.g., IntelliJ IDEA, Eclipse)
-
Clone the repository:
git clone https://github.com/yourusername/arithmetic-calculator.git cd arithmetic-calculator
-
Compile the code:
javac Stack.java Calculator.java
-
Run the calculator:
java Calculator input.txt output.txt
input.txt
should contain one expression per line.output.txt
will be generated with the results for each expression.
- Custom Stack: The
Stack
class provides methods to push, pop, and check if the stack is empty. - Calculator: The
Calculator
class evaluates expressions using the custom stack for both operators and operands.
Stack.java
: Implementation of the custom stack data structure.Calculator.java
: Contains the logic for parsing and evaluating arithmetic expressions.
- Time Complexity: The stack operations (push and pop) have an amortized time complexity of (O(1)). The overall time complexity of evaluating an arithmetic expression is (O(n)), where (n) is the length of the expression.
- Space Complexity: The space complexity is (O(n)), where (n) is the number of elements in the stack.
The calculator has been tested with various expressions to ensure its accuracy and robustness. Test cases include basic arithmetic operations, power functions, and complex nested expressions.
Contributions are welcome! Please open an issue or submit a pull request with your improvements or fixes.