Answered step by step
Verified Expert Solution
Question
1 Approved Answer
code in java public interface Graph { /** * The default capacity used when the no-argument constructor is called. */ static final int DEFAULT_CAPACITY =
code in java
public interface Graph { /** * The default capacity used when the no-argument constructor is called. */ static final int DEFAULT_CAPACITY = 1; /** * Returns the number of vertices in this graph (the "order" of this graph). * * @return the number of vertices in this graph */ int numberOfVertices(); /** * Returns the number of edges in this graph (the "size" of this graph). * * @return the number of edges in this graph */ int numberOfEdges(); /** * Creates and returns a new array of Strings containing the vertices of * this graph. The length of the returned array equals the number of * vertices. The order of the vertices is unspecified. * * @return a String array containing the vertex labels */ String[] getVertices(); /** * Creates and returns a new 2D array of strings containing the edges of * this graph. The size of the returned array is m x 2. In other words, * there is one row for each edge. The order of the edges is unspecified * and the order of the vertices in each edge is also unspecified. * For example, a graph with the three edges * {"A", "B"}, {"C", "A"}, and {"F", "D"} may return: * * { * {"A", "B"}, {"C", "A"}, {"F", "D"} } * * @return an m x 2 array in which each row represents and edge in this * graph. */ String[][] getEdges(); /** * Returns the number of vertices that can be added to this graph before * the array of vertices needs to be increased. * * @return the number of vertices that can be added to this graph before the * array of vertices needs to be increased. */ int capacity(); /** * Resizes the array of labels and the adjacency matrix to a new capacity. * If the new capacity is larger than the current capacity, the capacity is * increased. Note: In future assignment the capacity may also be made * smaller. * newCapacity. * * @param newCapacity The new capacity */ void resize(int newCapacity); /** * Determines if a vertex with the given label exists. * * @param vertex the label of a vertex. * @return true of the vertex exist, false if it does not exist. */ boolean vertexExists(String vertex); /** * Adds a new vertex to this graph. * * @param vertex the new vertex to be added * @throws GraphException if the specified vertex already exists. */ void addVertex(String vertex) throws GraphException; /** * Adds one or more vertices to this graph. * * @param vertices the vertices to be added */ void addVertices(String[] vertices); /** * Determines if an edge with the given end vertices exists. * * @param vertex1 the label of one end of the edge * @param vertex2 the label of the other end of the edge * @return true edge {vertex1, vertex2} is in this graph, returns false if * the edge is not in this graph * @throws GraphException if either vertex1 or vertex2 is not in this graph. */ boolean edgeExists(String vertex1, String vertex2) throws GraphException; /** * Adds a new edge. * * @param vertex1 the label of one end of the new edge * @param vertex2 the label of the other end of the new edge * @throws GraphException if the edge already exists or if either end vertex * does not exist. */ void addEdge(String vertex1, String vertex2) throws GraphException; /** * Adds multiple edges. Each row i in the edges parameter represents the * pair of vertices edges[i][0] and edges[i][1] for a new edge. * * @param edges a 2 x w array of vertices, w ≥ 0 */ void addEdges(String[][] edges); /** * Returns a string representation of this Graph. * * @return a string representation of this Graph. */ @Override String toString(); }Homework 03 - Graph Part 1 (20 points) Notec Homework cosgigrments, HW OS. HW O4. HW 67 . HW 13. and HW 15 are all related. Each of these asignments builds on the previcus assigrment. for tris assignment you cre to implament the inlerfoce named Graph. You wil add to your implamentation throughout the semasler, so it is important that you successfuly complete this assigrment. Details 1. Your closs musf be named stringGraph. 2. It must implement the interlace Graph. 3. Your cloas shoud not hove a main methed. If you want to test your clas, you thould write a seporate program. 4. You wil need to welte a cuatom emception caled Graph Excepson. 5. Your closs must have the following 5 instonce variables. A descriphion of the instance varcbles is provided in the lewadoc for this arianment. Notice that each of the irstance varibles is has the protected access medfier. - int eapacity - boleancll edgeMatro - Stringll labels - int numLidgas - int numvertioes b. Your closs must have the two canstructars descrbed in beavadoc tor the 7. Your closs must implement all the methods specilied in the Graph intertace. See the javipos comments for a desolption of each methed. B. Your class must include the woverise annatation tor each interface methods it implements. 9. The documentation for the StringGraph closs includes some addrional methods that not requied by the Graph interlace. These are included as bints cbout metheds you may wish to include in your class. You are not requered to include these addifional mathods. You are only required to implement the methods speofied in the Groph intertoce. Tester Program You are being provided with a Tester program, colled Graph_1_Tester.java. If your Stringaraph class b warking comectly the tester wil print a mesage indicoting that al tests were passed, otherwise emor messages will be printed. What to Tum in Compress the enthe folder creoted by NetBeans into a single ap hie and submit that zip fie through Blackboard. Your project should include the following fies: a. Graphjwa - You should downiood this fle and use it ai-is. Make no changes to this fie. b. Graph_1_Tesier java - You should dowrlood this fie and use it as-b. Make no ehanges to this fla. c. TestResaltiara - You should dowriood this file and use it as-is. Make no changes to this file. d. Graphemouptionjiava - This is your fie. e. Stringoraph.jpav - The is your fie
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started