Exception in thread "main" java.lang.Error: Unresolved compilation problem:      Tree cannot be resolved to a type     at Exercise28_05$UnweightedGraphWithGetPath.getPath(Exercise28_05.java:80)     at Exercise28_05.(Exercise28_05.java:35)     at Exercise28_05.main(Exercise28_05.java:8) Here is the part of my code that is experiencing issues: import java.util.*; import java.io.*; public class Exercise28_05  {   public static void main(String[] args) throws Exception    {     new Exercise28_05();   }      public Exercise28_05() throws Exception    {     String[] vertices = { "Seattle", "San Francisco", "Los Angeles", "Denver",         "Kansas City", "Chicago", "Boston", "New York", "Atlanta", "Miami",         "Dallas", "Houston" };     int[][] edges = { { 0, 1 }, { 0, 3 }, { 0, 5 }, { 1, 0 }, { 1, 2 },         { 1, 3 }, { 2, 1 }, { 2, 3 }, { 2, 4 }, { 2, 10 }, { 3, 0 }, { 3, 1 },         { 3, 2 }, { 3, 4 }, { 3, 5 }, { 4, 2 }, { 4, 3 }, { 4, 5 }, { 4, 7 },         { 4, 8 }, { 4, 10 }, { 5, 0 }, { 5, 3 }, { 5, 4 }, { 5, 6 }, { 5, 7 },         { 6, 5 }, { 6, 7 }, { 7, 4 }, { 7, 5 }, { 7, 6 }, { 7, 8 }, { 8, 4 },         { 8, 7 }, { 8, 9 }, { 8, 10 }, { 8, 11 }, { 9, 8 }, { 9, 11 },         { 10, 2 }, { 10, 4 }, { 10, 8 }, { 10, 11 }, { 11, 8 }, { 11, 9 },         { 11, 10 } };     UnweightedGraphWithGetPath graph = new UnweightedGraphWithGetPath<>(         vertices, edges);     Scanner input = new Scanner(System.in);     System.out.print("Enter a starting city: ");     String startingCity = input.nextLine();     System.out.print("Enter an ending city: ");     String endingCity = input.nextLine();     List list = graph.getPath(graph.getIndex(startingCity),         graph.getIndex(endingCity));     System.out.print("The path is ");     for (Integer i : list)      {       System.out.print(graph.getVertex(i) + " ");     }   } // BEGIN REVEL SUBMISSION   class UnweightedGraphWithGetPath extends UnweightedGraph    {     /** Construct an empty graph */     public UnweightedGraphWithGetPath()      {              }     /** Construct a graph from vertices and edges stored in arrays */     public UnweightedGraphWithGetPath(V[] vertices, int[][] edges)      {       super(vertices, edges);     }     /** Construct a graph from vertices and edges stored in List */     public UnweightedGraphWithGetPath(List vertices, List edges)      {       super(vertices, edges);     }     /** Construct a graph for integer vertices 0, 1, 2 and edge list */     public UnweightedGraphWithGetPath(List edges, int numberOfVertices)      {       super(edges, numberOfVertices);     }     /** Construct a graph from integer vertices 0, 1, and edge array */     public UnweightedGraphWithGetPath(int[][] edges, int numberOfVertices)      {       super(edges, numberOfVertices);     }     public List getPath(int u, int v)      {          Tree tree = bfs(u);            ArrayList path = new ArrayList<>();            do             {             path.add(v);             v = tree.parent[v];            } while (v != -1);            Collections.reverse(path);            return path;     }   }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Tree cannot be resolved to a type

    at Exercise28_05$UnweightedGraphWithGetPath.getPath(Exercise28_05.java:80)
    at Exercise28_05.<init>(Exercise28_05.java:35)
    at Exercise28_05.main(Exercise28_05.java:8)

Here is the part of my code that is experiencing issues:

import java.util.*;
import java.io.*;

public class Exercise28_05 
{
  public static void main(String[] args) throws Exception 
  {
    new Exercise28_05();
  }
  
  public Exercise28_05() throws Exception 
  {
    String[] vertices = { "Seattle", "San Francisco", "Los Angeles", "Denver",
        "Kansas City", "Chicago", "Boston", "New York", "Atlanta", "Miami",
        "Dallas", "Houston" };

    int[][] edges = { { 0, 1 }, { 0, 3 }, { 0, 5 }, { 1, 0 }, { 1, 2 },
        { 1, 3 }, { 2, 1 }, { 2, 3 }, { 2, 4 }, { 2, 10 }, { 3, 0 }, { 3, 1 },
        { 3, 2 }, { 3, 4 }, { 3, 5 }, { 4, 2 }, { 4, 3 }, { 4, 5 }, { 4, 7 },
        { 4, 8 }, { 4, 10 }, { 5, 0 }, { 5, 3 }, { 5, 4 }, { 5, 6 }, { 5, 7 },
        { 6, 5 }, { 6, 7 }, { 7, 4 }, { 7, 5 }, { 7, 6 }, { 7, 8 }, { 8, 4 },
        { 8, 7 }, { 8, 9 }, { 8, 10 }, { 8, 11 }, { 9, 8 }, { 9, 11 },
        { 10, 2 }, { 10, 4 }, { 10, 8 }, { 10, 11 }, { 11, 8 }, { 11, 9 },
        { 11, 10 } };

    UnweightedGraphWithGetPath<String> graph = new UnweightedGraphWithGetPath<>(
        vertices, edges);
    Scanner input = new Scanner(System.in);
    System.out.print("Enter a starting city: ");
    String startingCity = input.nextLine();

    System.out.print("Enter an ending city: ");
    String endingCity = input.nextLine();

    List<Integer> list = graph.getPath(graph.getIndex(startingCity),
        graph.getIndex(endingCity));

    System.out.print("The path is ");
    for (Integer i : list) 
    {
      System.out.print(graph.getVertex(i) + " ");
    }
  }

// BEGIN REVEL SUBMISSION
  class UnweightedGraphWithGetPath<V> extends UnweightedGraph<V> 
  {
    /** Construct an empty graph */
    public UnweightedGraphWithGetPath() 
    {
        
    }

    /** Construct a graph from vertices and edges stored in arrays */
    public UnweightedGraphWithGetPath(V[] vertices, int[][] edges) 
    {
      super(vertices, edges);
    }

    /** Construct a graph from vertices and edges stored in List */
    public UnweightedGraphWithGetPath(List<V> vertices, List<Edge> edges) 
    {
      super(vertices, edges);
    }

    /** Construct a graph for integer vertices 0, 1, 2 and edge list */
    public UnweightedGraphWithGetPath(List<Edge> edges, int numberOfVertices) 
    {
      super(edges, numberOfVertices);
    }

    /** Construct a graph from integer vertices 0, 1, and edge array */
    public UnweightedGraphWithGetPath(int[][] edges, int numberOfVertices) 
    {
      super(edges, numberOfVertices);
    }

    public List<Integer> getPath(int u, int v) 
    {
         Tree tree = bfs(u);
           ArrayList<Integer> path = new ArrayList<>();

           do 
           {
            path.add(v);
            v = tree.parent[v];
           } while (v != -1);

           Collections.reverse(path);
           return path;
    }
  }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Threads in linked list
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education