Question: Enhance the calculator program given in Figure 6.5 on page 330 so that it has all of the following features: After one expression is evaluated,

Enhance the calculator program given in Figure 6.5 on page 330 so that it has all of the following features: After one expression is evaluated, the user is asked if he or she wants to evaluate another expression and is allowed to choose between evaluating another expression and quitting the program. Expressions need not be fully parenthesized, and when parentheses are missing, the usual Java precedence rules are followed. If the arithmetic expression entered is not well formed, then the user is told that it is not well formed and is asked to re-enter the expression.

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

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

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.31 Rating (169 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres an enhanced version of the calculator program in Java that includes all the requested features ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures and Other Objects Using Java Questions!