You must implement an UndirectedGraph class that can represent the following graph.
Use the test code below to test out your graph implementation.
public class GraphTester {
public static void main(String [] args) {
UndirectedGraph graph = new UndirectedGraph(20); // maximum number of nodes is 20
graph.addNode("Chicago");
graph.addNode("Houston");
graph.addNode("Las Vegas");
graph.addNode("Miami");
graph.addNode("New York City");
graph.addEdge("Chicago", "Houston", 17);
graph.addEdge("Chicago", "New York City", 17);
graph.addEdge("Chicago", "Las Vegas", 3);
graph.addEdge("Las Vegas", "New York City", 9);
graph.addEdge("Las Vegas", "Miami", 4);
graph.addEdge("Las Vegas", "Houston", 8);
System.out.println("# of nodes is: " + graph.getOrder()); // should print 5
System.out.println("# of edges is : " + graph.getSize()); // should print 6
System.out.println(graph.getEdges("New York City")); // should print Las Vegas Chicago
System.out.println(graph.hasEdge("New York City", "Miami"); // should print false
System.out.println(graph.hasEdge("Houston", "Las Vegas"); // should print true
System.out.println( graph.getMatrix() ); // should print out the adjacency matrix
System.out.println( graph ); // should print out each node and its edges
}
}