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 6PC
Program Plan Intro

Binary Tree Input and Display

Program plan:

  • Import required packages.
  • Define the class named “JTreeDemo”.
    • Declare required private variables.
    • Define the constructor.
      • Initialize the values.
      • Load the “JTree”.
    • Give function definition “readData ()” to read data from the file.
      • Create the objects for “FileInputStream”, “InputStreamReader”, and “BufferedReader” in order to read the file
      • Declare variables “line”, and “countNode”.
      • Inside the “try” block,
        • Do until the file becomes empty using “while” condition.
          • Check if the line contains the given matches,
            • Assign the values to “numNodes”.
          • Else,
            • Assign line to “data[countNode]”.
            • Increment the value of “countNode”.
        • Close the file.
              • Catch the exception using “catch” block and print the exception.
    • Give function definition to populate the tree.
      • Create an object for “DefaultMutableTreeNode”.
      • Loop through the number of nodes.
        • Split the string.
        • Check if the length is greater than 1.
          • Add the node to the tree.
          • Loop through the length of node.
            • Add the node to the tree.
        • Check if the length is equal to 1.
          • Add the node to the tree.
              • Load the nodes to the tree.
    • Give function definition to create GUI.
      • Create a frame and add the tree to the frame.
      • Set the close operation and call the function “pack ()”.
      • Make the frame visible.
    • Give “main ()” function.
      • Assign a filename to the variable.
      • Create an object for the class.
      • Call the function “readData ()”.
      • Call the function “populateTree ()”.
      • Call the function “createAndShowGUI()”.

Blurred answer
Students have asked these similar questions
Domino cycledef domino_cycle(tiles):A single domino tile is represented as a two-tuple of its pip values, such as (2,5) or (6,6). This function should determine whether the given list of tiles forms a cycle so that each tile in the list ends with the exact same pip value that its successor tile starts with, the successor of the last tile being the first tile of the list since this is supposed to be a cycle instead of a chain. Return True if the given list of domino tiles form such a cycle, and False otherwise. tiles Expected result [(3, 5), (5, 2), (2, 3)] True [(4, 4)] True [] True [(2, 6)] False [(5, 2), (2, 3), (4, 5)] False [(4, 3), (3, 1)] False
struct nodeType {    int infoData;    nodeType * next; };   nodeType *first;   … and containing the values(see image) Using a loop to reach the end of the list, write a code segment that deletes all the nodes in the list. Ensure the code performs all memory ‘cleanup’ functions.
Arithmetic progression def arithmetic_progression(items): An arithmetic progression is a numerical sequence so that the stride between each two consecutive elements is constant throughout the sequence. For example, [4, 8, 12, 16, 20] is an arithmetic progression of length 5, starting from the value 4 with a stride of 4. Given a non-empty list items of positive integers in strictly ascending order, find and return the longest arithmetic progression whose all values exist somewhere in that sequence. Return the answer as a tuple (start, stride, n) of the values that define the progression. To ensure unique results to facilitate automated testing, if there exist several progressions of the same length, this function should return the one with the lowest start. If several progressions of equal length emanate from the lowest start, return the progression with the smallest stride. items expected results [42] (42, 0, 1) [2, 4, 6, 7, 8, 12, 17] (2, 2, 4) [1, 2, 36, 49, 50, 70, 75, 98,…
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
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning