Problem

Consider simple infix expressions that consist of single-digit operands; the operators +,...

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

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 7
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT