Question
Book Icon
Chapter 25, Problem 25.17PE
Program Plan Intro

Program Plan:

  • Include the required import statement.
  • Define the main class.
    • Declare the necessary variables
    • Using start initialize the required.
      • Create border pane, tree view, text field and button.
      • Set the tree view as center, alignment.
      • Add an action event to the button.
      • Create a scene and place the pane in the stage.
      • Set the title.
      • Place the scene in the stage.
      • Display the stage.
    • Define the main method using public static main.
      • Initialize the call.
    • Define “decode” method.
      • Declare the variable
      • Check the length of the “bits”.
        • If the “bits” value is “0” set that value into left subtree, if the “bits” value is “1” set the value into right subtree.
      • If the left subtree is null, leaf is detected and restart from the root.
      • Return the “result”.
    • Define “encode” method.
      • Declare and set the value.
      • Check the length of the “text”.
        • Calculate the result.
        • Return the “result”.
    • Define “getCode” method.
      • Check the “root” value is null
      • The variable “codes” is declared and allocates memory for that variable.
      • Call the “assignCode” method.
      • Return the “codes” value.
    • Define “assignCode” method.
      • Check if root of left subtree value is not null.
        • If the condition is true, calculate the left and right subtree value and call the “assignCode” method with the respective parameters.
      • Otherwise calculate the “root” element value.
    • Define “getHuffmanTree” method.
      • Create a heap to hold the trees.
      • Add the values into the heap tree.
      • If the heap tree is greater than 1, remove the smallest and next smallest weight from the tree and combine the two trees.
      • Finally return the tree.
    • Define “getCharacterFrequency” method.
      • Declare the variable.
      • The try-catch block is used to check the input file is present or not and count the number of characters in that file.
      • Return the total counts.
    • Define “TreeView” class.
      • Declare the required variables.
      • Define the constructor.
      • Define the “setTree” method.
        • Add the value.
        • Call the “repaint” method.
      • Define the “repaint” method.
        • Clear the pane
        • Display the tree recursively.
    • Define the “displayTree” method.
      • Check if the left node value is not equal to null.
        • Draw a line to the up node.
        • Draw the left subtree recursively.
      • Check if the right node value is not equal to null.
        • Draw a line to the down node.
        • Draw the left subtree recursively.
      • Display the node.
    • Define “Tree” class.
      • Declare the variable.
      • Create a tree with two subtrees,
      • Create a tree containing a leaf node.
      • Compare the trees based on their weights.
    • Define “Node” class.
      • Declare the required variables.
      • Create a default constructor.
      • Create a node with the particular weight and character.
    • Define “Heap” class.
      • Create the object for the ArrayList
      • Create the default constructor.
      • Create a heap from an array of objects.
      • Define “add” method.
        • Add the new object into the heap.
        • Check the “currentIndex” value is greater than 0.
          • Swap if the current object is greater than its parents.
          • Assign “parentIndex” value into “currentIndex” variable.
      • Define “remove” method.
        • Check the condition and remove the root from the heap.
        • Declare and compute the left and right child index.
        • Then find the maximum value between two children.
        • Swap if the current node is less than maximum value.
        • Finally return the value.

Blurred answer
Students have asked these similar questions
I would like to get help to resolve the following case
Last Chance Securities The IT director opened the department staff meeting today by saying, "I've got some good news and some bad news. The good news is that management approved the payroll system project this morning. The new system will reduce clerical time and errors, improve morale in the payroll department, and avoid possible fines and penalties for noncompliance. The bad news is that the system must be installed by January 1st in order to meet new federal reporting rules, all expenses from now on must be approved in advance, the system should have a modular design if possible, and the vice president of finance would like to announce the new system in a year-end report if it is ready by mid-December." Tasks 1. Why is it important to define the project scope? How would you define the scope of the payroll project in this case? 2. Review each constraint and identify its characteristics: present versus future, internal versus exter- nal, and mandatory versus desirable. 3. What…
2. Signed Integers Unsigned binary numbers work for natural numbers, but many calculations use negative numbers as well. To deal with this, a number of different methods have been used to represent signed numbers, but we will focus on two's complement, as it is the standard solution for representing signed integers. 2.1 Two's complement • Most significant bit has a negative value, all others are positive. So, the value of an n-digit -2 two's complement number can be written as: Σ2 2¹ di 2n-1 dn • Otherwise exactly the same as unsigned integers. i=0 - • A neat trick for flipping the sign of a two's complement number: flip all the bits (0 becomes 1, or 1 becomes 0) and then add 1 to the least significant bit. • Addition is exactly the same as with an unsigned number. 2.2 Exercises For questions 1-3, answer each one for the case of a two's complement number and an unsigned number, indicating if it cannot be answered with a specific representation. 1. (15 pts) What is the largest integer…
Knowledge Booster
Background pattern image
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
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning