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

  Multiple choice java programming questions

Determine which of the following may be a violation of information hiding if inserted for the comment above?

  Create a java class called samearraysexception

Create a Java class called SameArraysException that extends the Exception class.

  Write a program to find solution tocryparithmetic puzzle

Write a program (Crypta.java) that finds a solution to the cryparithmetic puzzle: TOO + TOO + TOO+ TOO = GOOD

  Variable is named res and is used to input a resistanc

Assume the existence of the following Java GUI application. There are two text fields for user input. The first JTextField variable is named res and is used to input a resistance value in ohms. The second JTextField variable named cap is used to..

  Array named peopletypes that can store a maximum

Define a 1-D array named peopleTypes that can store a maximum of 50 integer values that will be entered at the keyboard. Enter a series of 1's, 2's, 3's and 4's into the array, where a 1 represents an infant, a 2 represents a child, a 3 represents..

  Write java programming to show number of credits for course

Write the java programming to solve following problem. We are given a student's marks in Calculus 1, CS1, and Physics 1 (each mark being between 0 and 100) also number of credits for each course.

  Class diagram represents the relationship between parents

Draw a class diagram that represents the relationship between parents, children, and grandparents. Take into account that a person can have both a parent and a child. Annotate associations with roles and multiplicities.

  What are the values of these boolean expressions

Describe the steps for inserting a new item at the head of a linked list? Make sure you consider all possible incoming conditions.

  Displays every perfect number from 1 through 1000

Write an application that displays every perfect number from 1 through 1000. A perfect number is one that equals the sum of all the numbers that divide evenly into it.

  Directly cause thread to stop executing-thread execution

Which cannot directly cause a thread to stop executing? What is the name of the method used to start a thread execution?

  List various bindings that are needed to determine semantics

List the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

  Write a script and verify an logi by reading a file from xl

write a script and verify an logi by reading a file from xl sheet, first time only give the password and get an error message, second time give the email only and get an error message and third time give both email and correct password and get "Signe..

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