Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 21, Problem 4PC
Program Plan Intro

Prefix Calculator

Program plan:

  • Include necessary header files.
  • Define the class “PreficCalc”.
    • Declare the necessary variables.
    • Define the method “start()”.
      • Create labels and text fields to enter the prefix expression.
      • Create a button “evaluate” to submit and calculate the resultant value.
    • Define the class “CmdTextListener”.
      • Define the method “handle()”.
        • Declare the string variable to get a prefix expression.
        • Declare the method “buildExpr()” to read and build a binary tree.
        • Declare the method “eval()” to evaluate the tree expression.
        • Display the result into the resultant text field.
          • Define the method “eval()” to evaluate the expression.
            • The “if” statement check, left and right child of tree is equal to null.
              • True, return the integer value.
            • Otherwise,
              • Call the method “eval()” and assign the result into “leftOp”.
              • Call the method “eval()” and assign the result into “rightOp”.
              • The “if” statement check, tree value is equal to “*”.
                • True, return the multiplied value.
                  • The “if” statement check, tree value is equal to “+”.
                    • True, return the added value.
            • Return “0”.
              • Define the method “isNumber()”.
                • If the given expression is number then, return the number itself.
            • Define the class “Node”.
              • Declare the necessary variables.
              • Define the parameterized constructor.
            • Define the method “buildExpr()” to read and build a binary tree.
              • Read the input from the user.
              • The “if” statement check the expression is number.
                • True, return the node itself.
                  • Otherwise, build a non-leaf tree.
                    • Call the method “Node()” and return a value.
    • Define the “main()” method.
      • Declare the method “launch()” to call the “start()” method eventually.

Blurred answer
Students have asked these similar questions
Find the error, assume data is a string and all variables have been declared. for ch in data:         if ch.isupper:             num_upper = num_upper + 1         if ch.islower:             num_lower = num_lower + 1         if ch.isdigit:             num_digits = num_digits + 1         if ch.isspace:             num_space = num_space + 1
Find the Error: date_string = input('Enter a date in the format mm/dd/yyyy: ') date_list = date_string.split('-') month_num = int(date_list[0]) day = date_list[1] year = date_list[2] month_name = month_list[month_num - 1] long_date = month_name + ' ' + day + ', ' + year print(long_date)
Find the Error:       full_name = input ('Enter your full name: ')       name = split(full_name)       for string in name:         print(string[0].upper(), sep='', end='')         print('.', sep=' ', end='')
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning