Create a public class Connections with a single public constructor that accepts a String. The String contains, in CSV format, a list of cities and other cities that they are connected to. So, for...


Create a public class Connections with a single public constructor that accepts a String. The<br>String contains, in CSV format, a list of cities and other cities that they are connected to. So, for<br>example, the input:<br>Champaign,Chicago,St. Louis<br>Chicago,Detroit,Milwaukee<br>St. Louis,Champaign,Cincinnati<br>Means that Champaign is connected to Chicago and St. Louis, and that Chicago is connected to<br>Detroit and Milwaukee, and so on. Essentially the CSV serializes a directed graph, where the first<br>item on each line is a node and the other items represent other nodes that it is connected to.<br>This is one way of serializing a directed, unweighted graph. If the String passed to the<br>constructor is null, throw an IllegalArgumentException. Make sure to trimall the<br>Strings that you extract from the CSV.<br>Your class should parse this String and provide a single instance method isConnected.<br>isConnected accepts two Strings and returns true if the first city is connected to the second<br>based on the graph passed to the constructor. So, given the input above,<br>isConnected (

Extracted text: Create a public class Connections with a single public constructor that accepts a String. The String contains, in CSV format, a list of cities and other cities that they are connected to. So, for example, the input: Champaign,Chicago,St. Louis Chicago,Detroit,Milwaukee St. Louis,Champaign,Cincinnati Means that Champaign is connected to Chicago and St. Louis, and that Chicago is connected to Detroit and Milwaukee, and so on. Essentially the CSV serializes a directed graph, where the first item on each line is a node and the other items represent other nodes that it is connected to. This is one way of serializing a directed, unweighted graph. If the String passed to the constructor is null, throw an IllegalArgumentException. Make sure to trimall the Strings that you extract from the CSV. Your class should parse this String and provide a single instance method isConnected. isConnected accepts two Strings and returns true if the first city is connected to the second based on the graph passed to the constructor. So, given the input above, isConnected ("Champaign", "Chicago") would return true, but isConnected ("Chicago", "Champaign") would return false. (Note that the graph is not necessarily symmetric.) If either String passed to isConnected is null, or if you don't have connection information for the source, you should throw an IllegalArgumentException. Note that only the cities that appear first on each line in the CSV should be treated as cities you have connection information for. So, for example, even though "Detroit" appears as a destination from "Chicago" in the data set above, we do not have a line starting with "Detroit", and therefore a call to isConnected with "Detroit" as the first parameter should throw an IllegalArgumentException.
Our suggestion is to use a private field to store a data structure that you populate in your<br>constructor. This will keep your isConnected method simpler. Good luck, and have fun!<br>

Extracted text: Our suggestion is to use a private field to store a data structure that you populate in your constructor. This will keep your isConnected method simpler. Good luck, and have fun!
Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here