Package project2
Class Calculator
java.lang.Object
project2.Calculator
A class that converts infix expressions to postfix expressions and evaluates
postfix expressions.
Uses the LinkedStack and ResizableArrayStack classes.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> String
convertToPostfix
(String[] infix) Converts an infix expression to a postfix expression.evaluatePostfix
(String postfix, Integer[] valuesArray, char[] characters) Evaluates a postfix expression.static void
Main method.int
precedence
(String operator) Returns the precedence of an operator.
-
Constructor Details
-
Calculator
public Calculator()
-
-
Method Details
-
convertToPostfix
Converts an infix expression to a postfix expression.- Type Parameters:
T
- the type of the elements in the infix expression- Parameters:
infix
- the infix expression- Returns:
- the postfix expression
-
precedence
Returns the precedence of an operator.- Parameters:
operator
- the operator- Returns:
- the precedence of the operator
-
evaluatePostfix
Evaluates a postfix expression.- Parameters:
postfix
- the postfix expressionvaluesArray
- the values of the variables in the expressioncharacters
- the characters in the expression- Returns:
- the result of the expression
-
main
Main method.- Parameters:
args
- the command line arguments
-