Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I need some help with this problem please use JAVA, thanks. Needs to run as s

ID: 647059 • Letter: H

Question

Hi I need some help with this problem please use JAVA, thanks. Needs to run as shown in the example dialog below. Please finish the class file so it runs correctly.Thanks

Create a class which constructs a graph and performs a few graph operations. Test out your code with the driver.

//DRIVER:

//Graph CLASS FILE:

Download the class called Graph from here. It already has some instance variables and constructors. It is up to you to finish it by adding the following methods.

addVertex: this method which returns nothing and takes in a string parameter corresponding to the name of the new vertex. It will only add a new vertex if that name is not already in the list of vertices.

vertexIsContained: this method returns a true or false if there exists a vertex in the graph that matches the name passed in via the parameter.

addEdge: this method returns nothing and takes in two string parameters and a weight. The two string parameters correspond to the names of vertices and the weight is the weight of the newly created edge. The newly created edge is then placed in the neighbors edge list inside the first vertex. If either the first or second vertex doesnt exist the method should not continue.

getVertex: this method returns an instance of a vertex if the name (passed in via a parameter) is found in the vertex list.

printDFS: This prints out the vertices names in depth first order. You can find the algorithm the presentation provided.

printBFS: This prints out the vertices names in breadth first order. Like above you can find the algorithm in the presentation.

printLazyDFS: In the class there is an instance variable called maxDist which corresponds to the maximum distance that is allowed to travel. Write another DFS but make sure it doesnt traverse edges that are greater than the max distance.

Heres the graph the driver is based on

Example Print Out:

Adding verticies

Adding edges

Printing DFS

v1

v2

v4

v7

v6

v8

v5

v3

Printing BFS

v1

v2

v4

v6

v5

v7

v8

v3

Printing Lazy DFS

v1

v2

v4

v7

v6

Hi I need some help with this problem please use JAVA, thanks. Needs to run as shown in the example dialog below. Please finish the class file so it runs correctly.Thanks Create a class which constructs a graph and performs a few graph operations. Test out your code with the driver. //DRIVER: //Graph CLASS FILE: Download the class called Graph from here. It already has some instance variables and constructors. It is up to you to finish it by adding the following methods. addVertex: this method which returns nothing and takes in a string parameter corresponding to the name of the new vertex. It will only add a new vertex if that name is not already in the list of vertices. vertexIsContained: this method returns a true or false if there exists a vertex in the graph that matches the name passed in via the parameter. addEdge: this method returns nothing and takes in two string parameters and a weight. The two string parameters correspond to the names of vertices and the weight is the weight of the newly created edge. The newly created edge is then placed in the neighbor?s edge list inside the first vertex. If either the first or second vertex doesn?t exist the method should not continue. getVertex: this method returns an instance of a vertex if the name (passed in via a parameter) is found in the vertex list. printDFS: This prints out the vertices name?s in depth first order. You can find the algorithm the presentation provided. printBFS: This prints out the vertices name?s in breadth first order. Like above you can find the algorithm in the presentation. printLazyDFS: In the class there is an instance variable called maxDist which corresponds to the maximum distance that is allowed to travel. Write another DFS but make sure it doesn?t traverse edges that are greater than the max distance. Here?s the graph the driver is based on Example Print Out: Adding verticies Adding edges Printing DFS v1 v2 v4 v7 v6 v8 v5 v3 Printing BFS v1 v2 v4 v6 v5 v7 v8 v3 Printing Lazy DFS v1 v2 v4 v7 v6

Explanation / Answer

public void addVertex(String name){
   if(!vertexIsContained(name)){
       Vertex v=new Vertex(name);
   }
}

public boolean vertexIsContained(String name){
   if(verticies.contains(name)){
       return true;
   }
   return false;  
}

public void addEdge(String v1,String v2,double weight){
   Vertex v=new Vertex(v1);
   Edge e=new Edge(v1,weight);
}

public Vertex getVertex(String v1){
   for(int i=0;i<verticies.size();i++){
       if(verticies.get(i)==v1){
           return verticies.get(i);
       }
   }
}

public void printDFS(){
   Vertex vnode = this.Node;
        System.out.println(vnode.getValue());

        while (vnode != null) {
          if ( vnode.getLeftChild() != null ) {
              vnode = vnode.getLeftChild();
              System.out.println(vnode.getValue());
          } else if ( vnode.getRightChild() != null ) {
              vnode = vnode.getRightChild();
              System.out.println(vnode.getValue());

          }
          printDFS();
        }

}

public void printBFS(){
   Vertex vnode = this.Node;
        System.out.println(vnode.getValue());

        while (vnode != null) {
          if ( vnode.getLeftChild() != null ) {
              vnode = vnode.getLeftChild();
              System.out.println(vnode.getValue());
          } else if ( vnode.getRightChild() != null ) {
              vnode = vnode.getRightChild();
              System.out.println(vnode.getValue());

          }
          printDFS();
        }

}