Question: I need help with my route management system, aimed at calculating and optimizing routes between different locations using algorithms and data structures. Each location will
I need help with my route management system, aimed at calculating and optimizing routes between different locations using algorithms and data structures. Each location will be represented as a node in an undirected graph, and connections between locations will be modeled as edges. These edges should have weight and time attributes. All the methods to be used are in the LocationManager class, however, I feel like the main method is not presenting the menu as it should.
this task is based on a graph with nodes and edges adjacency matrix So when prompted to enter a location in the main method, it's to enter the name of the vertex, for example, node" and then specify how many edges it will have and to which nodes it will connect. However, the program is not doing that. I need to fix the main method. Help.
public class Main implements Serializable
public static void mainString args
Scanner scanner new ScannerSystemin;
LocationManager routeSystem new LocationManager; Example with locations
Add locations
while true
routeSystem.displayMenu;
int choice scanner.nextInt;
scanner.nextLine; Consume newline
switch choice
case :
System.out.printEnter location name: ;
String name scanner.nextLine;
routeSystem.addLocationnew Locationname;
break;
case :
System.out.printEnter index of location to edit: ;
int indexEdit scanner.nextInt;
scanner.nextLine; Consume newline
System.out.printEnter new location name: ;
String newName scanner.nextLine;
routeSystem.editLocationindexEdit new LocationnewName;
break;
case :
System.out.printEnter index of location to delete: ;
int indexDelete scanner.nextInt;
scanner.nextLine; Consume newline
routeSystem.deleteLocationindexDelete;
break;
case :
System.out.printEnter start location index: ;
int start scanner.nextInt;
System.out.printEnter end location index: ;
int end scanner.nextInt;
List shortestPath routeSystem.shortestPathDijkstrastart end;
System.out.printlnShortest Path: shortestPath;
break;
case :
routeSystem.minimumSpanningTreePrim;
break;
case :
routeSystem.minimumSpanningTreeKruskal;
break;
case :
routeSystem.shortestPathFloydWarshall;
break;
case :
routeSystem.minimizeTime;
break;
case :
routeSystem.minimizeDistance;
break;
case :
System.out.printlnExiting;
System.exit;
break;
default:
System.out.printlnInvalid choice. Please try again.";
public class LocationManager implements Serializable
private static final long serialVersionUID L;
private Edge matrizAdyacencia;
private List locations;
public LocationManagerint numLocations
matrizAdyacencia new EdgenumLocationsnumLocations;
locations new ArrayList;
public void setAdjacencyMatrixEdge matrizAdyacencia
this.matrizAdyacencia matrizAdyacencia;
public void getAdjacencyMatrixEdge matrizAdyacencia
this.matrizAdyacencia matrizAdyacencia;
public List getLocations
return locations;
public void setLocationsList locations
this.locations locations;
public void addLocationLocation location
locations.addlocation;
public void editLocationint index, Location location
if index && index locations.size
locations.setindex location;
public void addConnectionint source, int destination, int weight, int timeMin
if source && source locations.size &&
destination && destination locations.size
matrizAdyacenciasourcedestination new Edgeweight timeMin;
matrizAdyacenciadestinationsource new Edgeweight timeMin; Assuming undirected graph
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
