Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
Question
Book Icon
Chapter 29, Problem 29.12PE
Program Plan Intro

Display weighted graphs

Program Plan:

  • Create a package “main”.
    • Add a java class named “Edge” to the package which is used to get the edges from the graph.
    • Add a java class named “Graph” to the package which is used to add and remove vertices, edges.
    • Add a java class named “UnweightedGraph” to the package which is used to store vertices and neighbors.
    • Add a java class named “WeightedGraph” to the package which is used to get the weighted edges and print the edges.
    • Add a java class named “WeightedEdge” to the package which is used to compare edges.
    • Add a java class name “Displayable” to the package.
      • Declare the functions “get_X ()”, “get_Y ()”, “get_Name ()”.
    • Add a java class named “E12” to the package.
      • Declare the cities.
      • Declare an integer array.
      • Create an object for the weighted graph.
      • Create a graphview pane.
      • Declare “start ()” method that overrides the “start ()” method in the “Application” class.
        • Create a scene and place it on the stage.
        • Display the stage.
      • Declare the class “GraphView”.
        • The “Graph” class extends the interface “Displayable”.
        • Give the constructor for this class.
          • Set the graph and call the function “paint ()”.
        • Give function definition for “paint ()”.
          • Declare a list that extends Displayable.
          • Loop from 0 through size.
            • Get the vertices.
            • Get the name of the city.
            • Add the circle, text and vertices to the pane.
          • Loop from 0 through graph size.
            • Create a list.
            • Loop from 0 through neighbor’s size.
              • Get the vertices.
              • Inside the “try” block,
                • Add the line, text and vertices to the pane.
              • Inside the “catch” block,
                • Throw the exception.
      • Declare a class named “Cities”.
        • Declare required variables.
        • Give the constructor for this class which sets the name of the city, and the vertices.
        • Get and return the co-ordinate of the vertex “x”.
        • Get and return the co-ordinate of the vertex “y”.
        • Get and return the name of the city.
        • Declare function to compare cities.
          • Return the value.
      • Give the “main ()” method.
        • Launch the application.

Blurred answer
Students have asked these similar questions
please complete the following in JAVA Implement the graph ADT using the adjacency list structure. thanks! also posting a similar question for adjacency matrix. have a good day!
Evaluate the following Postfix expression to find the final value. Trace the evaluation using class PostfixEvaluator. Show the operand stack each time it is modified. (Clearly show all steps)             2         3          4           *          +           9        7       -        /
14.12 NVCC Lab: Count number of subsets of a graph   A graph is made up of a set of nodes called vertices and a set of lines called edges that connect the nodes. Informally, a connected component of a graph is a subset in which each pair of nodes is connected with each other via a path. For example, the following graph consists of two connected components (subsets).   For this assignment, you are required to find out the number of connected components in a graph as specified below: implement the following method: public static int countConnectedComponents(String fileName): where fileName is the input data file representing a graph: each line in the data file contains two numbers representing a pair of vertices that are connected (an edge between these two nodes exists). For example, given the following data file: 1 2 1 3 2 3 4 5 6 8 6 7   *Code must be written in JAVA
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