Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, %, and/; and parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces.
Design and implement a class for an infix calculator. Use the algorithms given in this chapter to convert the infix expression to postfix form and to evaluate the resulting postfix expression. Note that if the metodsevaluate andgetPostfix are called before dieconvertPostfix mediod, then the exceptionIllegalStateException should be dirown by these methods.
class Calculator {
public Calculator(String exp) // initializes infix expression
public String toString() // returns infix expression
private boolean convertPostfix() // creates postfix expression
// returns true if successful
// The following methods should throw IllegalStateException if // they are called before convertPostfix
// returns the resulting postfix expression
public String getPostfix() throws IllegalStateException
// evaluates the expression
public int evaluate() throws IllegalStateException > //end Calculator
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.