#Not Sure why this error?

7 messages · Page 1 of 1 (latest)

twin mason
#

My code

    // Task 3: Determine the mininum number of assistance cars required
    public int minNumAssistanceCars() {
        // Add your code here to compute and return the minimum number of assistance cars required for this map
        boolean [] visited = new boolean [numPlaces()];
        int Nodes = numPlaces();
        int count = 0;
        for (int i = 0; i<numPlaces();i++){
            if(!visited[i]){
                count++;
                DepthFirstSearch(getPlace(i),places,visited,Nodes);
            }
        }
        return count;
    }
    private void DepthFirstSearch(Vertex Node, ArrayList<Vertex> Stack, boolean[] visited, int Nodes){
        visited[Node.getIndex()] = true;
        for (int i = 0; i < Nodes;i++){
            if((Stack.get(Node.getIndex())).get(i) == 1 && !visited[i]){
                DepthFirstSearch(Node,Stack,visited,i);
            }
        }
    }```
the code i am referencing
```java
class Solution {
    private static void dfs(ArrayList<ArrayList<Integer>> adj,boolean[] visited,int src,int v){
        visited[src]=true;
        for(int i=0;i<v;i++){
            if(adj.get(src).get(i)==1 && !visited[i]){
                dfs(adj,visited,i,v);
            }
        }
    }
    static int numProvinces(ArrayList<ArrayList<Integer>> adj, int V) {
        // code here
        
        // crete graph
        int count=0;
       boolean[] visited=new boolean[V];
       for(int i=0;i<V;i++){
           if(!visited[i]){
               count++;
               dfs(adj,visited,i,V);
           }
       }
       return count;
    }
};```
valid yewBOT
#

This post has been reserved for your question.

Hey @twin mason! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

twin mason
#

I am struggling with the part java RoadMap.java:283: error: cannot find symbol if((Stack.get(Node.getIndex())).get(i) == 1 && !visited[i]){ ^ symbol: method get(int) location: class Vertex 1 error

#

I'm not sure why its getting an error??

#

Not Sure why this error?

hazy kettle
#

Java is quite affirmative that it is because the class Vertex doesn't have any such method get() that you're trying to call. Not one that takes an int as parameter at least