corrected function calls for estimating time and tolls in calculateRoutes to use appropriate vector formatting. added methods to set and get route modifier flags

This commit is contained in:
Fennel Kora 2024-04-14 01:09:14 -04:00
parent b99d8d55d8
commit d0a50ae260

View file

@ -20,24 +20,25 @@ public class Route {
private void calculateRoutes() { private void calculateRoutes() {
//execute api call out to routing service to get route info //execute api call out to routing service to get route info
//ideally a query would go out using multiple pathfiding algorithms to get route options //ideally a query would go out using multiple pathfiding algorithms to get route options
//here the same call is made for demo purposes
updateCurrentLocation(); updateCurrentLocation();
HelperFunctions apiCallToRouting = new HelperFunctions(); HelperFunctions apiCallToRouting = new HelperFunctions();
//route option 1 //route option 1
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag)); routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
timeEstimate[0] = estimateTime(routeSequences.get(0)); timeEstimate.add(estimateTime(routeSequences.get(0)));
estimateTolls(routeSequences.get(0)); tollsAmount.add(estimateTolls(routeSequences.get(0)));
//route option 2 //route option 2
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag)); routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
timeEstimate[1] = estimateTime(routeSequences.get(1)); timeEstimate.add(estimateTime(routeSequences.get(1)));
estimateTolls(routeSequences.get(1)); tollsAmount.add(estimateTolls(routeSequences.get(1)));
//route option 3 //route option 3
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag)); routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
timeEstimate[2] = estimateTime(routeSequences.get(2)); timeEstimate.add(estimateTime(routeSequences.get(2)));
estimateTolls(routeSequences.get(2)); tollsAmount.add(estimateTolls(routeSequences.get(2)));
} }
public int enumRoutes() { public int enumRoutes() {
return routeSequences.length; return routeSequences.size();
} }
public void selectRoute(int userSelection) { public void selectRoute(int userSelection) {
@ -46,10 +47,10 @@ public class Route {
public int getRouteSelected() {return routeSelected;} public int getRouteSelected() {return routeSelected;}
public float estimateTolls(double[][] route) { public float estimateTolls(Vector<String[]> route) {
float runningTolls = 0; float runningTolls = 0;
for (int i = 0; i <= route.length; i++) { for (String[] el : route) {
runningTolls += route[i][3]; runningTolls += Float.parseFloat(el[3]);
} }
return runningTolls; return runningTolls;
} }
@ -58,10 +59,15 @@ public class Route {
//calculates distances between route segments, divided by speed in MPH //calculates distances between route segments, divided by speed in MPH
//the API would return expected speed due to traffic conditions as part of the speed (index 2) in the route array //the API would return expected speed due to traffic conditions as part of the speed (index 2) in the route array
double runningTime = 0; double runningTime = 0;
//steps through subsequence route points to get distances, calculates time based on speed estimate, and accumulates on runningTime //steps through to get distances, calculates time based on speed estimate, and accumulates on runningTime
for (String[] el : route) { for (String[] el : route) {
runningTime += Double.parseDouble(el[1])/Double.parseDouble(el[2]); runningTime += Double.parseDouble(el[1])/Double.parseDouble(el[2]);
} }
return runningTime; return runningTime;
} }
public void setHwyFlag(boolean flag) {hwyFlag = flag;}
public void setTollsFlag(boolean flag) {tollsFlag = flag;}
public boolean getHwyFlag() {return hwyFlag;}
public boolean getTollsFlag() {return tollsFlag;}
} }