Question: Redo the calculator program given in Figure 6.5 on page 330, but this time implement it in a different way. To evaluate the arithmetic expression,
Redo the calculator program given in Figure 6.5 on page 330, but this time implement it in a different way. To evaluate the arithmetic expression, your program will first convert the expression to postfix notation. After that, it will evaluate the postfix expression. Pseudocode for both of these subtasks is given in this chapter. For this exercise, you should not assume that expressions are fully parenthesized. When parentheses are missing, the usual Java precedence rules are used to determine the order of evaluation. Your program should allow the user to evaluate additional expressions until the user wants to end the program.



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: IllegalArgumentException Indicates that the expression had the wrong format.
Step by Step Solution
3.48 Rating (165 Votes )
There are 3 Steps involved in it
import javautil public class Calculator public static void mainString args Scanner input new ScannerSystemin boolean keepGoing true while keepGoing Sy... View full answer
Get step-by-step solutions from verified subject matter experts
