Write class postfixevaluator to evaluate postfix expression

Assignment Help Programming Languages
Reference no: EM1355567

Write a class PostFixEvaluator that evaluates postfix expression such as 6 2 + 5 * 8 4 / -. The program should read a postfix expression consisting of digits and operators into a StringBuffer. Using modified version of Stack Data Structures(Abstract Data Structures -ADT) and it accompanying methods, your program should scan the expression and evaluate it ( assume it is legal/valid). The algorithm is as follows:

a. Append a # to the end of the postfix expression. When the# character is encountered, no further processing is necessary.
b. When the # character has not been encountered, read the expression from left to right.
i. If the character is a digit, do the following:

1. Push its integer value on the stack ( the integer value of a digit character is its value in the Unicode character set minus the value of '0' in Unicode.

2. Otherwise if the current character is an operator:

a. Pop the two top elements of the stack into variables x and y.
b. Calculate y operator x
c. Push the result of the calculation onto the stack.

3. When the # character is encountered in the expression, pop the top value of stack. This is the result of the postfix expression.

c. Note that in b above( based on the same expression at the beginning of this exercise), if the operator is '/' the top of the stack is 4 and the next element in the stack is 40 then pop 4 into x pop 40 into y, evaluate 40 / 4 and push the result, 10 back on the stack. This note also applies to operator '-'. This arithmetic operations allowed in an expression in an expression are:
+ - addition
- - subtraction
* - multiplication
/ -division
^ -exponentiation
% - remainder
The stack should be maintained with one of the stack classes introduced in this chapter. You may want to provide the following methods.
a) Method evaluatePostFixExpression, which evaluates the postfix expression
b) Method calculate, which evaluates the expression op1 operator op2.

Reference no: EM1355567

Questions Cloud

Essay reflecting on experience and communication style : Assistance with an essay reflecting on experience and communication style. Discuss how you can leverage your strengths and improve upon your communication skills to become a better leader.
Research three recent information security breaches : Research three recent information security breaches. Do main targets seem to be larger or smaller companies? Is there a particular industry which seems predominately targeted?
Crisis in public management : The concept in entrepreneurial government, out of those two do you know of examples that you can show that you feel may be more effective for reinventing the government and why.
Find the company float : A company receives an average of $11,000 in checks each day. The delay in clearing is typically 4-days. The current interest rate is .016% per day.
Write class postfixevaluator to evaluate postfix expression : Write a class PostFixEvaluator that evaluates postfix expression such as 6 2 + 5 * 8 4 / -. Program must read a postfix expression consisting of digits and operators into a StringBuffer.
Current global environment and effect on business : what are your thoughts about the global environment and what effect do you believe it has on the current and future US economy and business?
Basic elements of clinical assessment : Discuss the basic elements of clinical assessment. What is the role of the DSM IV-TR in clinical assessment? How does it guide the diagnosis of abnormal behavior?
Explain how did racism affect foreign affairs and discuss : Explain how did racism affect foreign affairs and discuss how the United States viewed some groups and the influence of the military abroad.
Effect on u.s. economy and business : Current Global Business Situation & Effect on U.S. Economy and Business - what effect do you believe it has on the current and future US economy and business?

Reviews

Write a Review

Programming Languages Questions & Answers

  Creating application to test class rectangle

Write down application to test class Rectangle.

  Program to multiply two integers

What occurs when you multiply two integers whose product is larger than largest int value? Try out example and report your findings.

  Pseudocode of program that will prompt user for number

Write pseudocode and flowchart for a program which will prompt user for a number, prompt the user for an operator (+,-,*,/), prompt the user for another number.

  Program to compute person-s body mass index

Write a program to compute person's body mass index? Create a modular program which calculates and display person's body mass index (BMI).

  Explaining tags used for effective page layout

Page layout is one of the most time consuming tasks for a web designer. What are some of the tags used for effective page layout and how do they work?

  Program to enter answer to a math problem

Write a program which ask student to enter an answer to a math problem. The user must enter two values, one at time, and then ask for answer.

  Subdividing address block among four different customers

The ISP needs to subdivide the address block among four different customers, requiring 29, 28, 27, and 26 hosts respectively.

  Create class templates for administrative employess

Create classes or class templates for the following: Administrative Employess are paid a salary, but they also receive a bonus at regular intervals during the year.

  Program to calculate and displays number of miles per hour

Design a program to calculate and displays the number of miles per hour over the speed limit that a speeding driver was doing

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Program to checks to see if the value of a is valid

Checks to see if the value of a is 0; if it is, the code prints the message "no solution for a=0" and returns from the function.

  Design and algorithm that compute numbers of married men

Design and algorithm that will read through the file and compute the numbers of married men, single men, married women and single women.

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