Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Problem Statement:

(The following problem is based on a problem in a number of Java texts, including the text by Gaddis.)

Given a numeric expression in prefix form, develop a Java program to evaluate the expression.

================================================================================

NOTE 1:

  • Your program should internally convert the prefix expression into a binary tree before evaluating it
  • Feel free to use any other data structures, in addition to the binary tree, that you may deem necessary to set up and evaluate your prefix expression

================================================================================

 

The following site provides some explanation on prefix expressions, as well as other forms of numeric expressions:

Infix, Prefix and Postfix Expressions (Links to an external site.) 

Input Data:

  • Repeatedly, enter one prefix expression (as a string) at a time at the keyboard
    • alternatively, you may set up an input data file and get the data from the file
  • Stop the inputting, when the user does not want to enter any additional strings

NOTE 1: To simplify matters,

    • assume that only non-negative integers are used
    • the allowed operations are binary addition and multiplication operations

Processing:

Set up a method (or methods) to evaluate the given expression.

 

Output Data:

         Echo back the entered input string, along with the result of the evaluation. 

          Example 1:

                The prefix expression is:  + 7  35

                 The expression evaluates to 42.

          Example 2:

                The prefix expression is:    *  +   16   4   +   3   1

                 The expression evaluates to   80.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education