Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For your first coding step, in your Project05.java file write a static method named readPathsFromFile with the following method signature: public static Map < String,

For your first coding step, in your Project05.java file write a static method named readPathsFromFile with the following method signature: public static Map< String, List > readPaths(String fname) This method should take a filename as an argument. It should create a new multimap, and then it should read paths from the file and store them in the multimap to make an adjacency list. Each line of the file will use the following format: node1,node2,distance For example, the graph above in the Overview section could be written in the file this way: Columbus,Chicago,0.5 Columbus,Miami,2.0 Chicago,NewYork,1.5 Chicago,Boston,2.0 Chicago,StLouis,0.5 Chicago,Denver,2.5 Chicago,Seattle,3.0 Boston,NewYork,0.5 StLouis,Atlanta,1 StLouis,Dallas,1.0 Atlanta,Dallas,1.0 Atlanta,Miami,1.0 Dallas,Miami,2.0 Dallas,LosAngeles,2.5 LosAngeles,SanFrancisco,1.0 LosAngeles,LasVegas,0.5 SanFrancisco,LasVegas,1.0 SanFrancisco,Seattle,2.0 SanFrancisco,Denver,2.0 Denver,LasVegas,1.0 Denver,Seattle,2.0 You can read in a line at a time and use the String split method to get out individual values from a line. For example, the following code will break up a comma separated line named input into an array of Strings (you will need to use the Double.parseDouble() method to turn the last element of the array into a Double value yourself): String[] tokens = input.split(","); Note that each path between nodes is listed only once, but each path needs to be added twice to the adjacency list. For example, the file lists a path between Columbus and Chicago on the first line. This needs to be added to the adjacency list for Columbus as a path with a destination of Chicago AND it needs to be added to the adjacency list for Chicago with a destination of Columbus (the same adjacency list structure can be used to show one-way paths, but all of the paths for this assignment work in both directions). Your code must be written to add both paths. Your code should also have a static method named displayPaths that has the following method signature: public static void displayAdjacencyList(Map< String,List > map) This method should display the entire adjacency list stored in the multimap named map that is passed in as a parameter. The output for this method should be similar to how the adjacency list is displayed above. For example, for the file give above, the following would be displayed: Miami: (Columbus:2.0), (Atlanta:1.0), (Dallas:2.0) SanFrancisco: (LosAngeles:1.0), (LasVegas:1.0), (Seattle:2.0), (Denver:2.0) Atlanta: (StLouis:1.0), (Dallas:1.0), (Miami:1.0) Chicago: (Columbus:0.5), (NewYork:1.5), (Boston:2.0), (StLouis:0.5), (Denver:2.5), (Seattle:3.0) Boston: (Chicago:2.0), (NewYork:0.5) StLouis: (Chicago:0.5), (Atlanta:1.0), (Dallas:1.0) NewYork: (Chicago:1.5), (Boston:0.5) LasVegas: (LosAngeles:0.5), (SanFrancisco:1.0), (Denver:1.0) Seattle: (Chicago:3.0), (SanFrancisco:2.0), (Denver:2.0) Columbus: (Chicago:0.5), (Miami:2.0) Denver: (Chicago:2.5), (SanFrancisco:2.0), (LasVegas:1.0), (Seattle:2.0) Dallas: (StLouis:1.0), (Atlanta:1.0), (Miami:2.0), (LosAngeles:2.5) LosAngeles: (Dallas:2.5), (SanFrancisco:1.0), (LasVegas:0.5) (Note that the ordering here is different than in the Overview section above. This output uses a HashMap as its underlying map - try calling the method with both a HashMap and a TreeMap to see the difference in output.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago