I need to create a disease transmission model using undirect

I need to create a disease transmission model using undirected graph (where we have 6 vertices and 10 edges). However, something went wrong and I can\'t see anything in my terminal. Can you please correct the errors and paste your code? Thank you so much.

Solution

//Try this code with modified code statemets

//Graph.java
import java.util.Scanner;
public class Graph {
  
   //Donot use final keyword for values
   //changable
   //declaration of instance variables
   private int V;
   private int E;

   private Bag<Integer>[] adj;
  
   //Constructor that sets number of vertices
   //of graph
   public Graph(int V) {
       this.V=V;
       adj=(Bag<Integer>[])new Bag[V];
      
       //create an object of Bag type of size V
       for (int v = 0; v < V; v++) {
           adj[v]=new Bag<Integer>();
       }
   }
  
   //Constructor that takes Scanner object
   public Graph(Scanner in)
   {
       this(in.readInt());
       E=in.readInt();
       for (int i = 0; i < E; i++) {
          
           int v=in.readInt();//read vertex
           int w=in.readInt();//read edge
           addEdge(v,w);

          
       }
   }

   private void addEdge(int v, int w) {
      
       //add w to vertex
       adj[v].add(w);
       //increment E by 1
       E++;      

   }
  
   public Iterable<Integer> adj(int v)
   {
       return adj[v];
   }

}

I need to create a disease transmission model using undirected graph (where we have 6 vertices and 10 edges). However, something went wrong and I can\'t see any

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site