I have been tasked to create a class 'GraphOfCity' that runs off and accounts for methods from a driver code included below.
Each time I make progress on GraphOfCity I end up doing something wrong and end up back to square one.
I have created a class 'Graph' as a placeholder, and class GraphOfCity extends Graph. This is about as far as I've gotten. I believe I need to use an Adjacency Matrix in order to carry everything out.
Methods that GraphOfCity needs to contain:
getSize()
getNeighbors()
getDegree()
isEmpty()
addVertex()
addEdge()
printEdges()
printVertices()
deleteEdge()
I have been trying for hours and have made no progress, thanks so much in advance!
Driver Code:
public class testcode01 {
public static void main(String args[])
{
Graph graph01 = new GraphOfCity();
String[] city = {"Little Rock", "Fayetteville", "Bentonville", "Fort Smith", "Harrison"};
int[][] distance =
{
{0, 92, 106, 136, 67},
{92, 0, 80, 120, 152},
{106, 80, 0, 209, 175},
{136, 120, 209, 0, 95},
{67, 152, 175, 95, 0}
};
Graph graph02 = new GraphOfCity(city, distance);
graph01.getSize();
graph02.getSize();
graph01.getNeighbors("Fayetteville");
graph02.getNeighbors("Fayetteville");
graph01.getDegree("Fayetteville");
graph02.getDegree("Fayetteville");
graph01.isEmpty();
graph02.isEmpty();
graph01.addVertex("Little Rock");
graph01.addVertex("Fayetteville");
graph01.addVertex("Bentonville");
graph01.addEdge("Little Rock", "Fayetteville", 45);
graph01.addEdge("Little Rock", "Bentonville", 142);
graph01.addEdge("Fayetteville", "Bentonville", 73);
graph01.printEdges();
graph01.printVertices();
graph02.printEdges();
graph02.printVertices();
graph01.deleteEdge("Fayetteville", "Bentonville");
graph01.deleteEdge("Fayetteville", "Bentonville");
graph02.deleteEdge("Fayetteville", "Bentonville");
graph02.deleteEdge("Fayetteville", "Bentonville");
}
}