1. Using any of the ADTS from the class implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, 4', ", *, ' operators, and open '(' and closing parentheses ')'. The integer division should truncate toward zero. You may assume that the given expression is always valid. Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval ().You'll have to fully implement the ADT, for example if you are using a Queue and in the below hint, you'll have to implement the Queue class that will be used. You are not allowed to use any implementations from java.utils.* Examples: Input: s = "1+1" Output: Input: s = "(2+6*3+5-(3*14/7+2)*5) +3" Output: -12 Input: s = "2* (5+5*2)/3+ (6/2+8)" Output: 21 Hint (not mandatory to be used): use stack with the Reverse Polish Notation. Reverse Polish Notation or Postfix notation is a mathematical notation in which operators follow their operands. For example infix notation: 3+5 is represented as 3,5,+ in postfix notation. Another example, infix notation 2* (5+5*2)/3+ (6/2+8) is represented as 2, 5,5,2,*,+,*,3,/,6,2,7,8,+,+in postfix notation. 2.

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
icon
Related questions
Question

Need help with this question. Must be answered using any ADT's from the class. Can use reverse polish notation. Make sure it is in java. All the info is in the image.

1. Using any of the ADTS from the class implement a basic calculator to evaluate a simple expression
string. The expression string contains only non-negative integers, +', '', **', ' operators, and open '(' and
closing parentheses ')'. The integer division should truncate toward zero. You may assume that the
given expression is always valid.
Note: You are not allowed to use any built-in function which evaluates strings as mathematical
expressions, such as eval ().You'll have to fully implement the ADT, for example if you are using
a Queue and in the below hint, you'll have to implement the Queue class that will be used. You
are not allowed to use any implementations from java.utils.*
Examples:
Input:
s = "1+1"
Output:
2
Input:
s = " (2+6*3+5- (3*14/7+2)*5)+3"
Output:
-12
Input:
s = "2* (5+5*2)/3+(6/2+8)"
Output:
21
Hint (not mandatory to be used): use stack with the Reverse Polish Notation.
Reverse Polish Notation or Postfix notation is a mathematical notation in which operators follow their
operands. For example infix notation: 3+5 is represented as 3,5,+ in postfix notation. Another example,
infix notation 2* (5+5*2)/3+(6/2+8) is represented as 2, 5,5,2,*,+,*,3,/,6,2,/,8,+,+in
postfix notation.
Transcribed Image Text:1. Using any of the ADTS from the class implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +', '', **', ' operators, and open '(' and closing parentheses ')'. The integer division should truncate toward zero. You may assume that the given expression is always valid. Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval ().You'll have to fully implement the ADT, for example if you are using a Queue and in the below hint, you'll have to implement the Queue class that will be used. You are not allowed to use any implementations from java.utils.* Examples: Input: s = "1+1" Output: 2 Input: s = " (2+6*3+5- (3*14/7+2)*5)+3" Output: -12 Input: s = "2* (5+5*2)/3+(6/2+8)" Output: 21 Hint (not mandatory to be used): use stack with the Reverse Polish Notation. Reverse Polish Notation or Postfix notation is a mathematical notation in which operators follow their operands. For example infix notation: 3+5 is represented as 3,5,+ in postfix notation. Another example, infix notation 2* (5+5*2)/3+(6/2+8) is represented as 2, 5,5,2,*,+,*,3,/,6,2,/,8,+,+in postfix notation.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education