Display the converted expression

Assignment Help Basic Computer Science
Reference no: EM13306416

You are to write a program name calculator.java that evaluates an infix expression entered by the user. The expression may contain the following tokens:
(1) Integer constants (a series of decimal digits).
(2) x (representing a value to be supplied later).
(3) Unary operators (+ and -).
(4) Binary operators (+, -, *, / and %).
(5) Parentheses
Spaces between tokens are allowed but not required. The program will convert the expression to postfix (RPN) form and display the converted expression. In the postfix version of the expression, unary + will be removed, and the unary - operator will be replaced by the _ (underscore) character. The program will repeatedly prompt the user for the value of x, displaying the result from evaluating the expression each time. When the user enters the letter q instead of a number, the program terminates.

The following example illustrates the behavior of the program (user input is in bold and red):
Porgram output is in bold and green.

Enter infix expression: (x + 1) * (x - 2) / -4
Converted expression: x 1 + x 2 - * 4 _ /

Enter value of x: 5
Answer to expression: -4

Enter value of x: 7
Answer to expression: -10

Enter value of x: q

If the infix expression contains an error of any kind, the program must display the message Error in expression (with an optional explanation) and then terminate. The following examples illustrate various types of errors:

Enter infix expression: 1 2 +
Error in expression!! No operator between operands. Also last token must be an operand.

Enter infix expression: 10.4
Error in expression!! Cannot accept floating point numbers.

Enter infix expression: 1 ( + 2)
Error in expression!! No operator between operand and left parentheses.

Enter infix expression: 5 - (x - 2))
Error in expression!! No matching left parentheses for a right parentheses.

Enter infix expression: 1 ** 2
Error in expression!! The * operator cannot be preceded by a * operator.

The output of your program must match the format illustrated in this example.

Here are some other additional requirements for this program:

(1) You must use stack objects during the translation from infix to postfix and during the evaluation of the postfix expression.

(2) Operators must have the correct precedence and associativity. Unary operators take precedence over *, % and /, which in turn take precedence over binary + and -. Unary operators are right associative; binary operators are left associative.

Reference no: EM13306416

Questions Cloud

How to sketch the hgl and the egl for the system : What power must the pump supply to the system to pump the oil from the lower reservoir to the upper reservoir at a rate of .2 m^3/s. Sketch the HGL and the EGL for the system.
Use a recursive function, instead of nested for loops : Write a C program that will prompt the user to enter an integer and then it will print on the screen all the binary numbers of length n, where n is the integer variable inserted by the user.
Practice using recursion with data structures : Write a recursive method in this class called hasSameStructureAs(BinaryTree tree) that returns whether or not a tree has the same structure as another tree.
Citing legal sources : Citing Legal Sources
Display the converted expression : Spaces between tokens are allowed but not required. The program will convert the expression to postfix (RPN) form and display the converted expression.
What are the angles for the first three dark fringes : A student sets up a double slit interference experiment using light of wavelength λ. The separation between the slits is 25λ. What are the angles for the first three dark fringes
Compute the spontaneous emission wavelength : Consider an optical gain medium that has two levels at E 1=1.50 eV and E 2=3.50 eV. What is the spontaneous emission wavelength
Write a recursive method that returns the total number : Write a recursive method that returns the total number of handshakes that took place in a room with n people.
How much water does the irrigator need to apply : An irrigator uses the (old-fashioned) concept of plant available water to determine the irrigation water quantity needed to irrigate a 10 ha field, How much water does the irrigator need to apply

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd