Adding some slight changes to Graph logic
This commit is contained in:
@@ -28,4 +28,14 @@ public class Graph {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeRoute(String src, String dst, int value) {
|
||||||
|
for(int i = 0; i < graph.size(); i++) {
|
||||||
|
String source = graph.get(i).source.getName();
|
||||||
|
String destination = graph.get(i).destination.getName();
|
||||||
|
if (source.equals(src) && destination.equals(dst)) {
|
||||||
|
graph.get(i).weight = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,9 +65,11 @@ public class Main {
|
|||||||
String source = scanner.nextLine();
|
String source = scanner.nextLine();
|
||||||
System.out.print("Destination: ");
|
System.out.print("Destination: ");
|
||||||
String destination = scanner.nextLine();
|
String destination = scanner.nextLine();
|
||||||
|
System.out.println("What is the new value?");
|
||||||
System.out.println("<------------------------------>");
|
System.out.println("<------------------------------>");
|
||||||
int value = graph.findRoute(source, destination);
|
int value = scanner.nextInt();
|
||||||
System.out.println("Route Cost: " + value);
|
graph.changeRoute(source, destination, value);
|
||||||
|
System.out.println("Route Changed!");
|
||||||
// END: Graphs
|
// END: Graphs
|
||||||
|
|
||||||
// System.out.println(addTotals(2.5, 2.5));
|
// System.out.println(addTotals(2.5, 2.5));
|
||||||
|
|||||||
Reference in New Issue
Block a user