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
Recursive PrintingDesign a recursive function that accepts an integer argument,n , and prints the numbers 1 up through n .
Recursive functions are ones that repeat themselves repeatedly.
Recursive Syntax The recursive structure i.e of natural language like English can be expressed in syntax rules written in the format known as BNF (Bachus-Naur Form). While BNF is ordinarily used as a guide for parsing (that is, determining whether and how a given string follows the syntax rules), An example of this can be found in the sample program SimpleRandomSentences. You should write a similar program that implements the following rules:<sentence> ::= <simple_sentence> [ <conjunction> <sentence> ]<simple_sentence> ::= <noun_phrase> <verb_phrase><noun_phrase> ::= <proper_noun> |<determiner> [ <adjective> ]. <common_noun> [ who <verb_phrase> ]<verb_phrase> ::= <intransitive_verb> |<transitive_verb> <noun_phrase> |is <adjective> |believes that <simple_sentence><conjunction> ::= and | or | but | because<proper_noun> ::= Fred | Jane | Richard Nixon | Miss…
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
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