Evaluate an infix expression entered by the user

Assignment Help JAVA Programming
Reference no: EM13313511

Objectives:

To gain experience with stacks and lists.

Documentation:

1.     Explain the purpose of the program as detail as possible

2.     Develop a solution for the problem and mention algorithms to be used

3.     List data structures to be used in solution.

4.     Give a description of how to use the program and expected input/output

5.     Explain the purpose of each class you develop in the program.

Programming:

1.     For each method, give the pre and post conditions and invariant, if any

2.     Program execution according to the requirements given

3.     Naming of program as required 5%

4.     Print out of source code 5%

Description of Program

You are to write a program name expressionTree.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)    One alphabetic character - "x" (representing a value to be supplied later).
(3)    Binary operators (+, -, *, / and % (modulo)).
(4)    Unary operators + & - 
(5)    Parentheses
          
You will parse the input expression creating an expression tree with the tokens, then use the postOrder tree traversal algorithm to extract a postfix expression from the tree. Display this postfixexpression(String).You will supply this postfix expression (string) to the calculator engine (a function that you will write) to produce a result. 
 
Spaces between tokens are allowed but not required. The program will repeatedly prompt the user for the value of x, displaying the value of 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):

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

Enter value of x: 5
Answer to expression: 97

Enter value of x: 7
Answer to expression: 165

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.

Reference no: EM13313511

Questions Cloud

Compute the mass in grams of the crystal : Iron pyrite, commonly known as "fool's gold," is 46.5% Fe and 53.5% S. A crystal of iron pyrite contains 4.24g of iron. A) Calculate the mass in grams of the crystal. B) How many moles of iron is in the crystal
Determine the temperature and mass in the tank : Initially the air in this tank is at 20 psia and 70 degrees F. Presuming that the ank is well insulated determine the temperature and mass in the tank when it is filled to 120 psia.
Find the final velocities of the blocks : Two blocks move along a linear path on a nearly frictionless air track. One block, of mass 0.104 kg, initially moves to the right at a speed of 5.20 m/s, Find the final velocities of the blocks
Define conjugate acid-base pairs to use in the preparation : Select all of the following that would be acceptable conjugate acid-base pairs to use in the preparation of a pH=9.8 buffer.
Evaluate an infix expression entered by the user : Spaces between tokens are allowed but not required. The program will repeatedly prompt the user for the value of x, displaying the value of the expression each time. When the user enters the letter q instead of a number, the program terminates.
What is the magnitude of torque : a person exerts force of 35n on the end of an door 88 cm wide, what is the magnitude of torque if the force is exerted perpendicular to the door
Which have user profiles that are available for transfer : Which have user profiles that are available for transfer?
The functions square and double take a single int parameter : The functions square and double take a single int parameter and return an int result.The function compute takes a value n and a function f, and returns the result of calling that function f with n as its parameter.So, compute(3,square) evaluate..
Provide kitchen staff with the functionality to display orde : Owners and managers have the ability to keep track of the inventories, quantities and item prices with additional functionality which allows for future orders to be implemented as required.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Creates pet objects from data read from the keyboard

The assignment is to write a program that creates Pet objects from data read from the keyboard. Store these objects into an instance of ArrayList.

  Create a class named blooddata

Create a class named BloodData that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor

  Write a program in java that reads contents of two vectors

Write a program in Java that reads contents of two vectors, and then displays the sum of these two vectors. The program should prompt the user to enter the size of the vectors first.

  Write a java program that prints the numbers from 1 to 125

Write a Java Program that prints the numbers from 1 to 125. But for multiles of three print "Batman" instead of the number and for the multiples of five print "Superman". For instances which are multiples of both three and five "JusticeLeague".

  Write an interface for an abstract method

Write an interface, PointingDevice, containing:  an abstract method, getXCoord that returns an int and an abstract method, getYCoord that returns an int.

  Prepare executable program and a dictionary program

Prepare executable program and a dictionary Program.

  Write an object-oriented java program to manipulate data

I want a simple java solution matching all the specifications in the document. The java program has to be made using Eclipseversion 4.2.1.

  Write a program that shows the current time and date

Write a program that shows the current time and date

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

  Implements both the quicksort and mergesort algorithms

Write a program that correctly implements both the Quicksort and Mergesort algorithms. The program should generate an array of 500 random numbers in the 1-100 range. The program should sort the same set of numbers and keep time stamps of how long it ..

  Use either an array or a linked list

Use either an Array or a Linked List as an underlying data structure. Of course you need to create class Array or class LinedList in order to implement the methods like mergeSort(), merge(), etc

  Create an application that provides a solution

Create an application that provides a solution for problem 20.8 In addition to requirements specified in the description.

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