Redo the calculator program given in Figure 6.5 on page 330, but this time implement it in
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, 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.
Transcribed Image Text:
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.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 90% (10 reviews)
import javautil public class Calculator public static void mainString args Scanner input new ScannerSystemin boolean keepGoing true while keepGoing Sy...View the full answer
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
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...
-
In Figure 6.5 on page 330, we presented a program to evaluate arithmetic expressions. In this exercise, you will write a similar program to evaluate boolean expressions. Rather than arithmetic...
-
Write a program that takes as input an infix expression and outputs the equivalent postfix expression. The basic algorithm is contained in Translating Infix to Postfix Notation on page 348. Assume...
-
The IASB's main objective is to develop a set of high-quality standards for financial reporting by companies at the international level. Required: Critically examine the possibility of achieving this...
-
As a manager, you must purchase light bulbs to be used in a hospital. Should you choose halogen bulbs that have lives with /x = 3000 h and a = 200 h, or should you choose compact fluorescent bulbs...
-
Examine the function for relative extrema and saddle points. z = -5x + 4xy - y + 16x + 10
-
Explain how and why physician incompetency is reported.
-
The trial balance of Boegner University, a government university, on September 1, 20X7, was as follows: Boegner Universitys dormitory and food service facilities are operated as auxiliary...
-
Bond value and time-Changing required returns Personal Finance Problem Lynn Parsons is considering investing in either of two outstanding bonds. The bonds both have $1,000 par values and 14% coupon...
-
Are the following functions analytic? Use (1) or (7). f(z) = Arg 2z
-
Write a program that evaluates an arithmetic expression in postfix notation. The basic algorithm is contained in Evaluating Postfix Expressions on page 345. Assume the input contains numbers (but no...
-
Write a program that evaluates an arithmetic expression in infix notation, without full parentheses. Use the following algorithm: There are two stacks: a numbers stack and an operators stack. When a...
-
Reestimate Eq. (17.13.16) imposing (1) near-end restriction, (2) far-end restriction, and (3) both end restrictions and compare your results given in Eq. (17.13.16). What general conclusion do you...
-
Over a period of four and half years an investment grows to $ 2 0 , 0 0 0 . ( a ) If money in this investment accummlated at a simple interest rate of 8 % , what was the initial amount for the...
-
A hospital germ-fighting and floor cleaning robot, named Maurice, costs $109,000. Patients are billed $1 per day for Maurice's use and upkeep. A certain 300-bed hospital is considering purchasing...
-
Firm 1 has two options: enter a new market (E) or stay out (O). If Firm 1 decides to enter the market, Firm 2, the incumbent, can either fight (F) or accommodate (A). If Firm 2 chooses to fight, Firm...
-
An industrial company is tired of subcontractors not being able to deliver parts on time. Delivery of a particular part is particularly critical for the company. This means that the management is...
-
Bob has a budget a Hockey $ 100 to host a HOCKEY Game night. A can of beer coasts $2.00, and a slice of Pizza is about $ 4.00. please derive the OC curve for BOB and indicate what would be the OC for...
-
Explain the major difference between an S corporation and an LLC?
-
Suppose Green Network Energy needs to raise money to finance its new manufacturing facility, but their CFO does not think the company is financially capable of making the periodic interest payments...
-
What is the best case time complexity for insertion sort to sort an array of n elements? A. (n) B. (n log n) C. (n 2 ) D. (n log n 2 )
-
Which of the following statements is false or true? 1. If an undirected simple graph of n vertices consists of n (n-1)/2 number of edges then it is called a complete graph. 2. A simple digraph is...
-
What are the different applications of DFS?
-
How do the mechanisms of ventilation and gas exchange operate synergistically in facilitating the diffusion of oxygen and carbon dioxide across the respiratory membrane, ensuring optimal...
-
How do environmental factors, such as altitude, temperature, and atmospheric composition, influence respiratory physiology, necessitating adaptive responses at both the cellular and systemic levels...
-
discuss the evolutionary adaptations of the respiratory system across taxa, highlighting the diversification of respiratory structures and mechanisms in response to ecological niches and selective...
Study smarter with the SolutionInn App