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: 81% (11 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...
-
Find the kinetic energy of an initially stationary electron after a 0.10-nm X-ray photon scatters from it at 90.
-
For a random sample of n = 49, find the probability of a sample mean being less than 37.2 when = 38 and = 2.17. The population mean and standard deviation are given. Find the indicated probability...
-
Blacktop Refining extracts minerals from ore mined at two different sites in Montana. Each ton of ore type 1 contains 20% copper, 20% zinc and 15% magnesium. Each ton of ore type 2 contains 30%...
-
On May 1, Soriano Company reported the following account balances along with their estimated fair values: Items Carrying Amount Fair Value Receivables Inventory Copyrights Patented technology Total...
-
A department store has purchased 5,000 swimsuits to be sold during the summer sales season. The season lasts three months and the store manager forecasts that customers buying early in the season are...
-
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...
-
The natural frequencies and mode-shape vectors for a \(n \mathrm{DOF}\) system have been determined. How is the free response of the system determined?
-
Explain the ethical dimensions associated with any health communication program.
-
Compare and contrast the effects of low health literacy and high health literacy.
-
Describe an activity that might be used to incorporate the three types of brain breaks discussed in the chapter. For each example, discuss a possible positive and negative outcome of incorporating...
-
What are the tones used in television advertising? Define each.
-
Define repositioning and explain under what circumstances a brand might be repositioned.
-
Shen purchased corporate stock for $20,000 on April 10, 2014. On July 14, 2016, when the stock was worth $12,000, Shen died and his son, Mijo, inherited the stock. Mijo sold the stock for $14,200 on...
-
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?
-
Do you envision the business as starting by targeting specific needs of a single target community (e.g. the target is San Francisco), targeting specific needs of a similar set of communities (e.g....
-
Define social media. ( 20 points ) How has social media changed the way marketers and consumers communicate with one another? Explain the implications for marketers. Describe how marketing managers...
-
Find an article or video offering advice on choosing the best financing option for a business. Answer the following questions: Which types of financing did they discuss? What advice did they offer?...
Study smarter with the SolutionInn App