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.
Data structure/ C language /  Graph /  Dijkstra’s algorithm implement a solution of a very common issue: how to get from one town to another using the shortest route.* design a solution that will let you find the shortest paths between two input points in a graph, representing cities and towns, using Dijkstra’s algorithm. Your program should allow the user to enter the input file containing information of roads connecting cities/towns. The program should then construct a graph based on the information provided from the file. The user should then be able to enter pairs of cities/towns and the algorithm should compute the shortest path between the two cities/towns entered.Attached a file containing a list of cities/towns with the following data:Field 1: Vertex ID of the 1st end of the segmentField 2: Vertex ID of the 2nd of the segmentField 3: Name of the townField 4: Distance in Kilometer Please note that all roads are two-ways. Meaning, a record may represent both the roads from…
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