Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, %, and/;...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, %, and/; and parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces. Design and implement a class for an infix calculator. Use the algorithms given in your textbook to convert the infix expression to postfix form and to evaluate the resulting postfix expression. Note that if the methods evaluate and getPostfix are called before the convertPostfix method, then the exception IllegalStateException should be thrown by these methods. class Calculator { public Calculator(String exp) // initializes infix expression public String toString() // returns infix expression private boolean convertPostfix() // creates postfix expression // returns true if successful // The following methods should throw IllegalStateException if // they are called before convertPostfix // returns the resulting postfix expression public String getPostfix() throws IllegalStateException // evaluates the expression public int evaluate() throws IllegalStateException } //end Calculator Question 2: Queue Application (50 marks) Write a Java program that reads integer values from a file that is attached here, then stores all negative values in one queue and all positive values in another queue. Then display all positive values and negative values separately. You can implement it by both ways: array-based and reference-based. Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, %, and/; and parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces. Design and implement a class for an infix calculator. Use the algorithms given in your textbook to convert the infix expression to postfix form and to evaluate the resulting postfix expression. Note that if the methods evaluate and getPostfix are called before the convertPostfix method, then the exception IllegalStateException should be thrown by these methods. class Calculator { public Calculator(String exp) // initializes infix expression public String toString() // returns infix expression private boolean convertPostfix() // creates postfix expression // returns true if successful // The following methods should throw IllegalStateException if // they are called before convertPostfix // returns the resulting postfix expression public String getPostfix() throws IllegalStateException // evaluates the expression public int evaluate() throws IllegalStateException } //end Calculator Question 2: Queue Application (50 marks) Write a Java program that reads integer values from a file that is attached here, then stores all negative values in one queue and all positive values in another queue. Then display all positive values and negative values separately. You can implement it by both ways: array-based and reference-based.
Expert Answer:
Answer rating: 100% (QA)
Heres a Java implementation for the Calculator class incorporating error handling and best practices ... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
A national fast food restaurant chain has recently made the decision that their breakfast menu will now be available all day long. The product management team overseeing the breakfast lines including...
-
Herd Mentality on page 303, we learned that it is common for investors to follow the investment lead of others. If they are all investing in dotcom firms or biotech firms, you might be swayed to jump...
-
Given the cost function in the following table for Simon, a housepainter in a competitive local market, answer the questions that follow. (You may want to calculate average cost.) Number of Rooms...
-
October 19, 1987, is an infamous day in financial history, better known as "the Black Monday of 1987." On that single day, the Dow Jones Industrial Average (DJIA) dropped by \(22.61 \%\), and other...
-
The following errors in the accounting records of the Chipp & Simon Partnership were discovered on January 10, 2011. The partners share net income and losses as follows: 65%, Chipp; 35%, Simon. 1....
-
A stock has a current selling price of $20. The distribution of the price of the stock one year from now is believed to be as follows: PRICE (x) PROBABILITY f(x) 20 .05 21 .06 22 .07 23 .08 24 .09 25...
-
X, Y and Z decided to form XYZ Partnership. It was agreed that X will contribute an equipment with assessed value of P300,000 with historical cost of P800,000 and accumulated depreciation of...
-
A metal sphere has an initial charge of + 8 mu C . What is the final charge on the sphere after 5 . 5 times 1 0 1 3 electrons have been placed on the sphere?
-
What are decorators in Python, and how do they contribute to the functionality of a program? Provide an example of a useful decorator.
-
How does firmware play a pivotal role in the operation and management of Internet of Things (IoT) devices, enabling functionalities such as sensor data acquisition, network communication, protocol...
-
I put together some supplemental practice problems you can use to learn the math required to calculate Contribution Margin, Contribution Rate, and Breakeven Point. Let me know if you have any...
-
Landmines Cheap and easy to deploy, many fighting forces routinely use mines to defend a frontier, deny opponents the use of a road, and many other purposes. Often these landmines remain active long...
-
1: You are the management consultant hired by a small firm that builds and sells kitchen cabinets for residential properties. You have estimated that the firm's daily production function is given by...
-
You continue to work in the corporate office for a nationwide convenience store franchise that operates nearly 10,000 stores. The per- store daily customer count (i.e., the mean number of customers...
-
(Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance...
-
Modify Figs. 21.15 and 21.16 so the Tree class provides a method getDepth that determines how many levels are in the tree. Test the method in an application that inserts 20 random integers into a...
-
Using only the programming techniques you learned in this chapter, write an application that calculates the squares and cubes of the numbers from 0 to 10 and prints the resulting values in table...
-
A strain rosette consisting of three strain gauges was used to measure the strains at a point in a thin plate of dimensions \(100 \times 20 \times 1 \mathrm{~mm}\). The measured strains in the three...
-
A particle of mass \(m\) slides inside a smooth hemispherical bowl of radius \(R\). Beginning with spherical coordinates \(r, \theta\) and \(\varphi\) to describe the dynamics, select generalized...
-
Two blocks of equal mass \(m\), connected by a Hooke's-law spring of unstretched length \(\ell\), are free to move in one dimension. Find the equations of motion of the system, using the relative and...
Study smarter with the SolutionInn App