Hello,
I have an assignment that I'm working on, I have completed every thing but one part, the toString of the Graph Class. I am having a hard time creating my toString.
The professor wants us to use both the vertexIterator and the outEdges methods in the Graph class to represent our toString. Here is the code I wrote in the Graph class.
import java.util.*; public class Graph { private List<Edge> outEdge; private List<Vertex> verticies; private List<Edge> edges; private int numberEdges; private int numberVertices; public Graph() { numberVertices = 0; numberEdges = 0; verticies = new ArrayList<Vertex>(); edges = new ArrayList<Edge>(); } public void addVertex(Vertex v) { numberVertices++; verticies.add(v); outEdge = v.getAdjacentList(); } public void addEdge(Edge e) { numberEdges++; edges.add(e); outEdge.add(e); } public int numVertices() { return numberVertices; } public int numEdges() { return numberEdges; } public Iterator outEdges(Vertex v) { //outEdge = v.getAdjacentList(); return v.outEdges(); } public Iterator vertexIterator() { return verticies.iterator(); } public String toString() { StringBuffer tmp = new StringBuffer(); for(Iterator vIterator = vertexIterator(); vIterator.hasNext(); ) Vertex v = (Vertex) vIterator.next(); tmp.append("outgoing edges from vertex: "); for (Iterator it = v.outEdges(v); it.hasNext(); ) { Edge s = (Edge)it.next(); tmp.append(s); } return tmp.toString(); } }
This is the error message I'm getting
This is literally the final part of my project. I don't know how to get the Vertex section correct. Any help will be greatly appreciated.Graph.java:68: not a statement
Vertex v = (Vertex) vIterator.next();
^
Graph.java:68: ';' expected
Vertex v = (Vertex) vIterator.next();
^
2 errors
If you need the rest of my code, I can provide it.