I have discussed briefly in class how a stack can be used to evaluate normal mathematical expression (by normal, I mean infix notation expression). I proposed doing it in two phases: Converting an infix to a postfix expression. Evaluating the postfix expression. Both algorithms where discussed in class, and it was explained that a stack data structure is needed to implement both algorithm phases.
I have discussed briefly in class how a stack can be used to evaluate normal mathematical expression (by normal, I mean infix notation expression). I proposed doing it in two phases: Converting an infix to a postfix expression. Evaluating the postfix expression. Both algorithms where discussed in class, and it was explained that a stack data structure is needed to implement both algorithm phases.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%

Transcribed Image Text:I have discussed briefly in class how a stack can be used to evaluate normal mathematical expression
(by normal, I mean infix notation expression). I proposed doing it in two phases:
Converting an infix to a postfix expression.
Evaluating the postfix expression.
Both algorithms where discussed in class, and it was explained that a stack data structure is needed
to implement both algorithm phases.
When dealing with postfix expression, two edge issues need to be handled:
First, regarding negative numbers, it is important to distinguish the unary negative sign (such us -5)
from the binary subtraction operation (such us 3-5) in your implementation code. For example, one
way is to substitute the unary symbol from - (minus) to another symbol (such as ~), and consider it as
part of the operand, not an operation: for example ~5 is the (minus five operand). That substitution
should be only implemented internally, but the program should still accept it. Of course, you can come
up with alternative ways how to resolve it.
Second, postfix expression can have two operands (numbers) next to each other. You might need to
separate operands with space, in order be able to handle expression properly.
As a requirement, you program should accept the same entry as in the infix expression with space
separating characters, such as:
((2+3)/5)-1
((-2+7)/3)*17
It should display to the user the evaluation of the expression. However:
Division is a integer division, no decimals. Division by zero should trigger an error.
You have to implement the two phases explained above clearly in your code, in separate
method.
Your code should accept negative numbers. A negative number will have the "-" sign
attached (like -2, not-2), no space between - and 2.
Your code should use a JAVA Stack class, part of the Java 1.8 API.
If you need to implement multiple classes, each class should be in its own file.
Adhere to the general assignment guidelines, and make sure to include the UML part of
your deliverables.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education