Question: Please help! public class DirectedWeightedExampleSlide18 { public static void main(String[] args) { int currentVertex, userChoice; Scanner input = new Scanner(System.in); // create graph using your

Please help!
public class DirectedWeightedExampleSlide18
{
public static void main(String[] args)
{
int currentVertex, userChoice;
Scanner input = new Scanner(System.in);
// create graph using your WeightedGraph based on author's Graph
WeightedGraph myGraph = new WeightedGraph(4);
// add labels
myGraph.setLabel(0,"Spot zero");
myGraph.setLabel(1,"Spot one");
myGraph.setLabel(2,"Spot two");
myGraph.setLabel(3,"Spot three");
// Add each edge (this directed Graph has 5 edges,
// so we add 5 edges)
myGraph.addEdge(0,2,9);
myGraph.addEdge(1,0,7);
myGraph.addEdge(2,3,12);
myGraph.addEdge(3,0,15);
myGraph.addEdge(3,1,6);
// let's pretend we are on v2
currentVertex = 2;
// do - this is a good place for the top of the loop
// display the current vertex
System.out.println(" You are currently at vertex " + currentVertex +
"-" + myGraph.getLabel(currentVertex));
// who are our neighbors?
System.out.println("neighbors of " + currentVertex + " are: ");
System.out.printf("%3s %-10s %4s ","#","Neighbor","Cost");
System.out.printf("%3s %-10s %4s ","===","==========","====");
if (myGraph.neighbors(currentVertex).length == 0)
System.out.println("No Neighbors");
else
{
for (int neighbor : myGraph.neighbors(currentVertex))
{
System.out.printf("%3d %-10s %4d ",
neighbor,
myGraph.getLabel(neighbor),
myGraph.getWeight(currentVertex,neighbor));
}
System.out.println();
}
// suppose I was interacting with user,
// I could ask for their choice
/* 1: if their choice is -1 then say goodbye
2: else if the user enters a value too large or too small report an out of range error
3: else if their choice is a valid neighbor then change the current vertex to that choice
4: else then report the vertex they entered is unreachable
hint for 3:
else if myGraph.isEdge(currentVertex,choice)
currentVertex=choice;
*/
// while...this is a good place for the bottom of the loop
System.out.println(" you need to modify this file: \tDirectedWeightedExampleSlide18.java"+
" press enter to continue...");
input.nextLine();
}
}
 Please help! public class DirectedWeightedExampleSlide18 { public static void main(String[] args)

undirected non-weighted graph from slide 19 (see a later page) and uses Graph. It allows the 'user' to meander around the Graph. Implement WeightedGraph and use it in a program In the zip files is WeightedGraph.java and DirectedWeightedExampleSlide18.java The WeightedGraph.java has only stubs implemented. . Add the fields . Fill in the constructor Complete the 9 methods The DirectedWeightedExampleSlide 18.java has the statements to create the directed weighted graph from slide 18 .Add the logic to allow the 'user' to meander around the graph

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!