writing a program that allows the user to enter a binary tree in a parenthesized prefix...
Fantastic news! We've Found the answer you've been seeking!
Question:
![writing a program that allows the user to enter a binary tree in a parenthesized prefix format and then](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/10/652641b87e685_1697006007152.jpg)
![Binary Tree Categorizer Make Tree Enter Tree: (A(G(X1))(z(5))) Is Balanced? Is Full? Output: ((()) G (1)) A](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/10/652642392d3dd_1697006110394.jpg)
Transcribed Image Text:
writing a program that allows the user to enter a binary tree in a parenthesized prefix format and then allows it to be categorized and allows various features of that tree to be displayed. An example of a tree written in the input format is the following: (A(G(j) (1)) (z (5))) In the above example, data in each node of the tree contains a single alphanumeric character. No spaces are permitted. Each tree is enclosed in parentheses. Inside those parentheses, after the single character are either zero, one or two subtrees also enclosed in parentheses. When only one subtree is present, it is the left subtree and when two are present, they represent the left and right subtrees. So the above string represents the following binary tree: The various categorizations include the following: 1. Whether the binary tree is balanced, which means for each node in the tree, the absolute difference between the height of its left and right subtrees is at most 1. The above binary tree is balanced. 2. Whether the binary tree is full. A full binary tree has the maximum number of nodes for a tree of its height. The above tree is not full because a tree of that height can contain 7 nodes, but the above tree only has 6. 3. Whether the binary tree is proper. In a proper binary tree, every node has either 0 or 2 children. The above tree is not proper because the node containing z has only one child. In addition, the program should allow the user to request that each of the following features of the tree be displayed: 1. The height of the tree. The height of a tree is the maximum level of all of its nodes. The root node containing A is at the level 0. Because all three leaf nodes in the above tree are at level 2, its height is 2. 2. The number of nodes in the tree. As previously mentioned, the above tree has 6 nodes. 3. An fully parenthesized inorder traversal of the tree. The following should be displayed as the inorder traversal of the above tree: ((() G (1)) A ((5) Z )) This project should consist of three classes. The main class should create a GUI that allows the user to input a tree in the above described format and then construct the tree once the Make Tree button is clicked. The GUI should look as follows: Binary Tree Categorizer Make Tree Enter Tree: (A(G(X1))(z(5))) Is Balanced? Is Full? Output: ((()) G (1)) A (( 5 )z)) Is Proper? Height Nodes X Inorder The GUI must be generated by code that you write. You may not use a drag-and-drop GUI generator. The second class should be the BinaryTree class, which should contain a static nested class to define the nodes of the binary tree, together with a constructor that is called when the Make Tree button is clicked and is supplied the string representation of the tree and constructs the actual tree from that string. In addition, it should have public methods that are called when each of the remaining six buttons are clicked. All of those public methods should have corresponding private methods that accomplish their tasks using recursion. The third class should be named InvalidTreeSyntax, which defines a checked exception. It should be thrown when a invalid string is supplied and the Make Tree button is clicked. It should be caught in the main class and a JOptionPane window should be displayed that describes the reason for the invalid syntax. a. A UML class diagram that includes all classes you wrote. Do not include predefined classes. You need only include the class name for each individual class, not the variables or methods b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing c. A short paragraph on lessons learned from the project writing a program that allows the user to enter a binary tree in a parenthesized prefix format and then allows it to be categorized and allows various features of that tree to be displayed. An example of a tree written in the input format is the following: (A(G(j) (1)) (z (5))) In the above example, data in each node of the tree contains a single alphanumeric character. No spaces are permitted. Each tree is enclosed in parentheses. Inside those parentheses, after the single character are either zero, one or two subtrees also enclosed in parentheses. When only one subtree is present, it is the left subtree and when two are present, they represent the left and right subtrees. So the above string represents the following binary tree: The various categorizations include the following: 1. Whether the binary tree is balanced, which means for each node in the tree, the absolute difference between the height of its left and right subtrees is at most 1. The above binary tree is balanced. 2. Whether the binary tree is full. A full binary tree has the maximum number of nodes for a tree of its height. The above tree is not full because a tree of that height can contain 7 nodes, but the above tree only has 6. 3. Whether the binary tree is proper. In a proper binary tree, every node has either 0 or 2 children. The above tree is not proper because the node containing z has only one child. In addition, the program should allow the user to request that each of the following features of the tree be displayed: 1. The height of the tree. The height of a tree is the maximum level of all of its nodes. The root node containing A is at the level 0. Because all three leaf nodes in the above tree are at level 2, its height is 2. 2. The number of nodes in the tree. As previously mentioned, the above tree has 6 nodes. 3. An fully parenthesized inorder traversal of the tree. The following should be displayed as the inorder traversal of the above tree: ((() G (1)) A ((5) Z )) This project should consist of three classes. The main class should create a GUI that allows the user to input a tree in the above described format and then construct the tree once the Make Tree button is clicked. The GUI should look as follows: Binary Tree Categorizer Make Tree Enter Tree: (A(G(X1))(z(5))) Is Balanced? Is Full? Output: ((()) G (1)) A (( 5 )z)) Is Proper? Height Nodes X Inorder The GUI must be generated by code that you write. You may not use a drag-and-drop GUI generator. The second class should be the BinaryTree class, which should contain a static nested class to define the nodes of the binary tree, together with a constructor that is called when the Make Tree button is clicked and is supplied the string representation of the tree and constructs the actual tree from that string. In addition, it should have public methods that are called when each of the remaining six buttons are clicked. All of those public methods should have corresponding private methods that accomplish their tasks using recursion. The third class should be named InvalidTreeSyntax, which defines a checked exception. It should be thrown when a invalid string is supplied and the Make Tree button is clicked. It should be caught in the main class and a JOptionPane window should be displayed that describes the reason for the invalid syntax. a. A UML class diagram that includes all classes you wrote. Do not include predefined classes. You need only include the class name for each individual class, not the variables or methods b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing c. A short paragraph on lessons learned from the project
Expert Answer:
Answer rating: 100% (QA)
Below is an example implementation of the three classes MainClass BinaryTree and InvalidTreeSyntax Please note that this is just one possible implementation and you can modify it according to your spe... View the full answer
Related Book For
Systems Analysis And Design
ISBN: 978-1119496489
7th Edition
Authors: Alan Dennis, Barbara Wixom, Roberta M. Roth
Posted Date:
Students also viewed these programming questions
-
Write a 3- to 5-page essay tracing the evolution of thought on governance from Plato, Aristotle, and Aquinas through to Locke and Hobbes. How are Locke and Hobbes like their predecessors? How are...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
The second programming project involves writing a program that examines a file of polynomials and determines whether the polynomials in that file are in strictly ascending order using two different...
-
PROJECT SCENARIO You are recently appointed as the IT Consultant and Software Architect in BMS a Software Architect firm. As your first project, you are assigned by the Project Manager to propose and...
-
(a) What is a trial balance? (b) From what source document(s) is it prepared?
-
The two largest values in a correlation matrix are the 0.850 correlation between y and x4, and the 0.790 correlation between y and x9. During a stepwise regression analysis, x4 is the first...
-
Fosters Group Limited and Heineken N.V. are two well-known beer companies. Fosters is an Australian company, and Heineken is Dutch. Fosters is about half the size of Heineken. Ratios can help in...
-
Is any option that Mary is considering acceptable under generally accepted accounting principles? Why or why not? Do any of the options considered by Mary constitute financial statements fraud? How...
-
What is the future value of $625 deposited for one year earning an 8 percent interest rate annually? (Do not round intermediate calculations. Enter your answer as a whole number.)
-
Target Corporation reported the following on its income statement. For 12 Months Ended ($ millions) Feb. 2, 2019 Feb. 3, 2018 Jan. 28, 2017 Total revenue $75,356 $72,714 $70,271 Cost of sales 53,299...
-
Marco Pollo, the President of Cheap Chicken, Inc., supplies restaurants with (you might guess this) cheap chicken. In order to keep down costs, he always sells his entire inventory even as the...
-
What are the key considerations for businesses when expanding into new international markets, and what strategies can they employ to mitigate risks and maximize opportunities?
-
What are the key factors that contribute to successful business partnerships, and how can companies establish and maintain mutually beneficial partnerships?
-
What are the emerging trends and opportunities in the e-commerce industry, and how can businesses capitalize on them to drive growth?
-
What are the key strategies for businesses to attract and retain top talent in a competitive labor market?
-
What are the key drivers of customer loyalty in today's highly competitive market, and how can businesses effectively build and maintain customer loyalty?
-
Door to Door Moving Company is considering purchasing new equipment that costs $700,000. Its management estimates that the equipment will generate cash inflows as follows: Year 1 $206,000 2 206,000 3...
-
Describe a group you belong or have belonged discuss the stages of group development and suggest how to improve the group effectiveness by using the group development model.
-
What are the six general skills all project team members should have?
-
Examine the data models that you created for Exercise D. How would the respective models change (if at all) on the basis of these corresponding new assumptions? Two patients have the same first and...
-
Select a specific project management topic like CASE, project management software, or timeboxing, and use the Web search for information on that topic. The URL listed in exercise 5 or any search...
-
Refer to CVS Corporations annual report in the Supplement to Chapter 1 to answer the following questions: 1. What amount of cash and cash equivalents did CVS Corporation have in 2004? Do you suppose...
-
On the last day of August, Navarro Company borrowed $120,000 on a bank note for 60 days at 10 percent interest. Assume that interest is stated separately. Prepare the following entries in journal...
-
The following payroll totals for the month of April are from the payroll register of Ha Corporation: salaries, $446,000; federal income taxes withheld, $62,880; social security tax withheld, $27,652;...
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App