Question: Rewrite the basic calculator program from Figure 6.5 so that the method evaluate uses recursion instead of stacks. FIGURE 6.5 A Method to Evaluate a
Rewrite the basic calculator program from Figure 6.5 so that the method evaluate uses recursion instead of stacks.



FIGURE 6.5 A Method to Evaluate a Fully Parenthesized Arithmetic Expression Method Specification and Implementation evaluate public static double evaluate(String expression) The evaluate method evaluates the arithmetic expression. Parameter: expression- a fully parenthesized arithmetic expression Precondition: The expression must be a fully parenthesized arithmetic expression formed from double numbers (with no + or-sign in front), any of the four arithmetic operations (+,-*, or /), and spaces. Returns: the value of the arithmetic expression Throws: I1legalArgumentException Indicates that the expression had the wrong format.
Step by Step Solution
3.37 Rating (169 Votes )
There are 3 Steps involved in it
Answer Here evaluateHelper is a recursive method that evaluates a mathematical expression starting a... View full answer
Get step-by-step solutions from verified subject matter experts
