Question: JAVA Using the three files given, produce the following: Write a program called ShortestDistances that: 1. Reads the list of cities into a string array

JAVA
Using the three files given, produce the following:
 JAVA Using the three files given, produce the following: Write a

Write a program called ShortestDistances that: 1. Reads the list of cities into a string array using StdIn.readAllStrings() and then builds a symbol table where the key is the name of a city and the value is an integer from 0 to the number of cities minus one. The first city gets 0, the second gets 1, and so forth 2. Reads the list of major cities into a string array using StdIn.readAllstrings). 3. Creates an empty undirected graph using the class algs41.Graph. In this graph, each vertex represents a city. As we discussed, the vertices of an undirected graph are labelled with non- negative integers. When the vertices represent real world objects, this makes it difficult to connect a vertex's integer label with its real world label. You will use the symbol table just constructed to make this connection. 4, Reads in each connection from the connections data file, one line at a time, where each line contains the names of two cities. As it reads in each line, it adds an edge to the graph. To do this, it will have to translate from the cities given on each connection line to their corresponding vertex numbers. S. Prints a header line for the table to follow (see code below for printing this header). 6. For each city o Creates a BreadthFirstPaths object with that city as the starting verterx o For each major city Prints the shortest distance from the major city to the city in the outer loop Here is an example of the first few lines of expected output: Chicago KansasCity Milwaukee Minneapolis Saintlouis Alton Appleton Carbondale Carlinville 10 To print the header line, use code something like this: stdout ,printf("%20s",""); for (String majorCity: majorCities) ( Stdout.printf-12s", majorCity); Stdout.println); Print each numeric entry in the table formatted using the format string %3d ". That's four spaces before the specifier and five after. Grading rubric The program is worth 20 points. Code that doesn't compile or that compiles and then crashes will be given 0 points. The 20 points will be alllocated as follows Reading the data files into arrays properly (2 points) Building the symbol table correctly (3 points); . Building the graph correctly (5 points: Having the correct logic in the outer loop (5 points): Having the correct logic in the inner loop (5 points)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!