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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

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

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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