Ask Computer Engineering Expert

This 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 generic Stack class like the one given in lecture.
The standard algorithm for evaluating expressions of this style is to use two stacks - one
stack for operators (the operator stack) and the other for operands/subexpression values
(the operand stack). 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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91008131

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As