Question Get Answer

" I need help for this programming, 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: ((( j ) G ( 1 )) A (( 5 ) z )) This project should consist of three classes. The main class should make 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: 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. 

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Java Programming tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes