-3

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");

}

}

CS_J
  • 1
  • 2

1 Answers1

0

Without the code of your Graph class, we won't be able to tell much. Where do you get stuck?

Mykee
  • 1
  • This was all the code given. I've created another 'Graph' class as a placeholder and made GraphOfCity to extend graph. After this I've tried a few different things to get the GraphOfCity class headed in the right direction, but I'm very fuzzy on the implementation of the adjacency matrix and how to implement all of the requested methods. Thanks! – CS_J Feb 03 '21 at 18:49