Adding some slight changes to Graph logic

This commit is contained in:
Frank
2025-09-01 23:57:13 -06:00
parent f59ba4cd54
commit 7ceece79d2
2 changed files with 14 additions and 2 deletions

View File

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

View File

@@ -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));