Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 22, 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
We are considering the RSA encryption scheme. The involved numbers are small, so the communication is insecure.  Alice's public key (n,public_key) is (247,7). A code breaker manages to factories  247 = 13 x 19  Determine Alice's secret key. To solve the problem, you need not use the extended Euclid algorithm, but you may assume that her private key is one of the following numbers 31,35,55,59,77,89.
Consider the following Turing Machine (TM). Does the TM halt if it begins on the empty tape? If it halts, after how many steps? Does the TM halt if it begins on a tape that contains a single letter A followed by blanks? Justify your answer.
Pllleasassseee ssiiirrrr soolveee thissssss questionnnnnnn
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