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
Union-Find: Maze Write a program that generates mazes of arbitrary size using the union-find algorithm. A simple algorithm to generate the maze is to start by creating an N x M grid of cells separated by walls on all sides, except for entrance and exit. Then continually choose a wall randomly, and knock it down if the cells are not already connected to each other. If we repeat the process until the starting and ending cells are connected, we have a maze. It is better to continue knocking down the walls until every cell is reachable from every cell as this would generate more false leads in the maze. Test you algorithm by creating a 15 x 15 grid, and print all the walls that have been knocked down. D
2). Write a program to implement the following graph representations and display them. i. Adjacency list ii. Adjacency matrix
C++ A program applying the topics involved in data structures (linked list, graph, array etc.) 1. User will be asked to login/signup 2. User will choose for the nearest restaurant (undirected graph?) 3. User will add to cart (from the menu list of the restaurant) 4. User will be asked for order confirmation and mode of payment (cash on delivery, card??) note: new users will have a discount 5. Invoice Using Dev c++
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education