
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;
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- How did you decide to handle the possibility of queue underflow in java? A. Assume as a precondition that it will not occur. B. Provide an isEmpty operation so a client can prevent underflow. C. Ignore it. D. Throw a QueueUnderflowException if it occurs. E. Throw a QueueUnderflowException if it occurs, and provide an isEmpty operation so a client can prevent underflowarrow_forwardFor the following code I get an error: Exception in thread "main" java.lang.Error: Unresolved compilation problems: The type LinkedListIn is not generic; it cannot be parameterized with arguments <String> The type LinkedListIn is not generic; it cannot be parameterized with arguments <> at linkedList.LinkedListTester.main(LinkedListTester.java:5) How can I fix it? package linkedList; public class LinkedListTester { public static void main(String[] args) { LinkedListIn<String> list = new LinkedListIn<>(); list.display(); list.add("Station 1"); list.add("Station 2"); list.add("Station 3"); list.add("Station 4"); // Print the linked list System.out.println("All Stations: " + list); // Accessing the first item System.out.println("First stop: " + list.getFirst()); // Accessing the last item System.out.println("Last stop: " + list.getLast()); // Removing the first item System.out.println("Left this station: " + list.removeFirst()); //…arrow_forward1. Show the ListStackADT<T> interface 2. Create a ListStackDataStrucClass<T> with the following methods: defaultconstructor, overloaded constructor, copy constructor, getTop, setTop,isEmpty, ifEmpty (if empty throw the exception), push, peek, pop, toString. 3. Create a private inner class of ListStack<T> called StackNode<T> with thefollowing methods: default constructor, overloaded constructor, copyconstructor, getValue, getNext, setValue, setNext 4. Create a BaseConverter class (non-generic) with the following methods: defaultconstructor, inputPrompt, convert [converts a BaseNumber to a convertedString], convertAll [instantiate a String object] , toString, processAndPrint 5. Create a private inner class BaseNumber. The inner class has the following methods: default constructor, overloaded constructor, getNumber, getBase,setNumber, setBase. [Make your private instance variables in the inner classLong type]. 6. Create a BaseConverterDemo class that only…arrow_forward
- TRUE OR FALSE We can use Generics to define a custom generic exception.arrow_forwardThe program inserts a number of values into a priority queue and then removes them. The priority queue treats a larger unsigned integer as a higher priority than a smaller value. The priority queue object keeps a count of the basic operations performed during its lifetime to date, and that count is available via an accessor. In one or two places I have put statements such as op_count++;, but these are incomplete. We only count operations involved in inserting and removing elements, not auxiliary operations such as is_empty() or size() The class implements a priority queue with an unsorted vector. Your assignment is to re-implement the priority queue implementation using a heap built on a vector, exactly as we discussed in class. Leave the framework and public method interfaces completely unchanged. My original test program must work with your new class. You will have to write new private methods bubble_up and percolate_down. You should not implement heapify or heapsort. #include…arrow_forwardCreate the Singly Linked List after having executed the following methods. Each item must have a headand tailreference. Whenever a method is not expected or invalid, write Exception. Only the process not the code •addHead("Dancing") •addHead("Backup") •addHead("Backup") •addTail("Backup") •addTail("Backup") •removeHead()arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





