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
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
- The “if” statement check, tree value is equal to “+”.
- True, return the multiplied value.
- Return “0”.
- Define the method “isNumber()”.
- If the given expression is number then, return the number itself.
- Define the method “isNumber()”.
- 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.
- Otherwise, build a non-leaf tree.
- True, return the node itself.
- The “if” statement check, left and right child of tree is equal to null.
- Define the method “handle()”.
- Define the “main()” method.
- Declare the method “launch()” to call the “start()” method eventually.
Expert Solution & Answer
Trending nowThis is a popular solution!
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…
Chapter 21 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 21.1 - Prob. 21.2CPCh. 21.1 - Prob. 21.3CPCh. 21 - Prob. 1MCCh. 21 - Prob. 2MCCh. 21 - Prob. 3MCCh. 21 - Prob. 4MCCh. 21 - Prob. 5MCCh. 21 - Prob. 6MCCh. 21 - Prob. 7MCCh. 21 - Prob. 8MC
Ch. 21 - Prob. 9MCCh. 21 - Prob. 10MCCh. 21 - Prob. 11TFCh. 21 - Prob. 12TFCh. 21 - Prob. 13TFCh. 21 - Prob. 14TFCh. 21 - Prob. 15TFCh. 21 - Prob. 16TFCh. 21 - Prob. 17TFCh. 21 - Prob. 18TFCh. 21 - Prob. 19TFCh. 21 - Prob. 20TFCh. 21 - Prob. 21TFCh. 21 - Prob. 1FTECh. 21 - Prob. 2FTECh. 21 - Prob. 3FTECh. 21 - Prob. 1SACh. 21 - Prob. 2SACh. 21 - Prob. 3SACh. 21 - Prob. 4SACh. 21 - What is a priority queue?Ch. 21 - Prob. 6SACh. 21 - Prob. 7SACh. 21 - Prob. 1AWCh. 21 - Prob. 2AWCh. 21 - Prob. 3AWCh. 21 - Prob. 4AWCh. 21 - Prob. 5AWCh. 21 - Prob. 6AWCh. 21 - Prob. 7AWCh. 21 - Prob. 4PCCh. 21 - Prob. 6PC
Knowledge Booster
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
- PythonDesign a recursive function that accepts an integer argument, n, and prints the number 1 up through n.arrow_forward7. Recursive Power Method In Python, design a function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised, and the exponent. Assume the exponent is a nonnegative integer.arrow_forwardExplain differences between recursive and non recursive functions.arrow_forward
- C languagearrow_forwardTrue/False 5. All proper recursive definitions must have exactly one non-recursive base case.arrow_forwardC Language Explain the terms infix expression, prefix expression, and postfix expression. Convert the following infix expressions to their postfix and prefix equivalents: (a) A * B + C (b) A / B * C - D (c) A + (B - C) / D * (E + F) Thank youarrow_forward
- T/F 1. Infinite recursion occurs where a recursive form lacks a base case.arrow_forwardRecursive function that returns the minimum of the numbers in C PROGRAMMING LANGUAGE PLEASE AND COMMENT EVERY-LINE SO THAT I COULD UNDERSTAND WHAT IS HAPPENINGarrow_forwardDefine the term " operator prefix increment " .arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning