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.
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.
|