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.11PE
Program Plan Intro

Find shortest paths

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 named “Test” to the package.
      • Import the required packages.
      • Declare the main class.
        • Give the “main ()” method.
          • Get the URL from the user.
          • Open the URL and read the string.
          • Get the number of vertices and store it in the variable “num”.
          • Print the number of vertices.
          • Create an array list.
          • Loop until End of file using “while” condition.
            • Read the line.
            • Split the string.
            • Loop through the length of the triplet.
              • Create an array and add the tokens.
              • Trim the edges and add the edges to the array list.
          • Create an object for the “WeightedGraph”.
          • Print the edges by calling the function “printWeightedEdges ()”.
          • Call the function “getShortestPath ()”.
          • Print the total weight of the minimum spanning tree.
          • Call the function “printPath ()”.

Blurred answer
Students have asked these similar questions
<<Write in Java>> - Challenge 7 File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a simple one of your own. For example, you could read the first file one character at a time, and add 10 to the character code of each character before it is written to the second file.   - Challenge 8 Write a program that decrypts the file produced by the program in Programming Challenge 7. The decryption program should read the contents of the coded file, restore the data to its original state, and write it to another file
*Code in python Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number. An example file and the program input and output is shown below: example.txt Line 1.Line 2.Line 3. Enter the input file name: example.txt The file has 3 lines. Enter a line number [0 to quit]: 2 2 : Line 2. The file has 3 lines. Enter a line number [0 to quit]: 4 ERROR: line number must be less than 3. The file has 3 lines. Enter a line number [0 to quit]: 0 Make sure the program gracefully handles a user entering a line number that is too high.
3) Implement the if __name__ == "__main__" : block at the bottom of this file to do the following: 3a) The if main block at the bottom should get the name of the highway graph file from the command line arguments.  See the video in Python that explains how to get command line arguments.  3b) Call your parse_highway_graph_file function to parse that file, and to construct a WeightedGraph object from it.  3c) Write some code that outputs (with print statements) the degree of each vertex. You can have one vertex per line, indicating its id (just its 0-based index) followed by its degree.  IMPORTANT: Your parse_highway_graph_file function should NOT produce any output. You will have code in your if main block that will have the print statements. The WeightedGraph class has a degree method, inherited from Graph that will return to you the degree of a vertex.
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