Integer expression evaluator

Assignment Help JAVA Programming
Reference no: EM13552222

Program must use stacks in order to evaluate integer expressions. Your program need only implement the following binary operators:

+ ... addition
- ... subtraction
* ... multiplication
/ ... integer division
< ... minimum (e.g. 3 < 2 yields 2)
> ... maximum (e.g. 3 > 2 yields 3)

To keep the assignment somewhat more manageable you may assume that all input integers are unsigned single decimal digits (0-9). However, your evaluation may result in larger and/or negative integers.

The evaluation of expressions must recognize the standard precedence:

< and > have the highest precedence
* and / have the middle precedence
+ and - have lowest precedence

Expressions must also permit the usual use of parentheses (...) to override precedence.

Below are several examples of proper expressions:

1+2*3>4

(24-7)/2+6<3*(31-299)

2*3*4*5*6

10>9*8+7+2

Your program must read input expressions from a text file and allow the user to select which text file to process using a JFileChooser. You may assume that each line of the text file is a separate integer expression and that there are no blanks or other invalid characters in the file.

For each input expression your program should output (using System.out.println) the input line followed by "==" then followed by the numeric value of the resulting expressions evaluation.

You must implement a bounded generic Stack class. Represent your Stack using an array to hold the stack content. (An array with a maximum of one hundred cells will be more than adequate.)

The standard algorithm for evaluating expressions of this style is to use two stacks - one stack for operators and the other for operands/subexpression values. An expression is processed left to right as follows:

• Each operand encountered is pushed upon the operand stack.

• Each left paren encountered is pushed upon the operator stack.

• Each right paren causes operators to be popped from the operator stack and the associated subexpressions evaluated until a left paren is found in the operator stack. The left paren is then popped.

• Each operator has its precedence compared to the precedence of the operator atop the operator stack. Operators are popped off the operator stack and their corresponding subexpressions evaluated until the top of the operator stack is either a left paren or has a precedence less than the new operator. After evaluating subexpressions, the new operator is pushed onto the operator stack.

• At the end of the expression all operators on the operator stack must be popped and their corresponding subexpressions evaluated. The value of the expression should be the single remaining value atop the operand stack.

When the prior explanations refer to "popping an operator and evaluating the corresponding subexpression" this means that the operand stack should be popped twice, and the two popped operands are evaluated using the popped operator with the resulting value pushed on the operand stack. For example, if the top of the operand stack is a 7 and the second operand in the operand stack is a 3 and the operator is a "-", then all three of these are popped and the result of the subexpression 3-7 (i.e., the value -4) is pushed on the operand stack.

Reference no: EM13552222

Questions Cloud

Estimate the density of the solvent : A cylindrical storage tank has a radius of 1.20 m. When filled to a height of 3.99 m, it holds 13800 kg of a liquid industrial solvent. What is the density of the solvent
Identify a global organization with a multinational presence : Identify a global organization with a multinational presence.
Estimate what is the pressure of the steam : Steam moves into the cylinder of a steam engine at a constant pressure and does 9.650 J of work on a piston. What is the pressure of the steam
Evaluate the percent relative error for the the solutions : A 50-ml transfer pipet and a 200-ml volumetric flask (To Contain) is used to make 0.500 M and 0.125 M solutions from a stock solution of 2.000±0.005 M. Calculate the percent relative error for the three solutions if perfect technique is used. Repo..
Integer expression evaluator : You must implement a bounded generic Stack class. Represent your Stack using an array to hold the stack content - Integer Expression Evaluator
Personal selling and sales objectives : Personal Selling and Sales Objectives
Electron beam on a photographic plate placed perpendicular : A beam of electrons traveling with speed 0.8 x10^(8) m/s passes through a slit of width 10^(-5) m. Because of the uncertainty in the lateral position of the beam, there will be an uncertainty in the transverse momentum as well.
Obtain the width of the first-order bright fringe : Light of wavelength 5.30 102 nm passes through a slit of width 0.230 mm. Determine the width of the first-order bright fringe
Explain small amount of unreacted starting material : Suppose a reaction has the equilibrium constant k= 1.7 x 10^-8 at a particular temperature. Will there be a large or small amount of unreacted starting material present when this reaction reaches equilibrium

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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