From d0a50ae260f81e4626fae01b47607318099df6c0 Mon Sep 17 00:00:00 2001 From: Fennel Kora Date: Sun, 14 Apr 2024 01:09:14 -0400 Subject: [PATCH] corrected function calls for estimating time and tolls in calculateRoutes to use appropriate vector formatting. added methods to set and get route modifier flags --- Route.java | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Route.java b/Route.java index a48c565..db091f3 100644 --- a/Route.java +++ b/Route.java @@ -20,24 +20,25 @@ public class Route { private void calculateRoutes() { //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 + //here the same call is made for demo purposes updateCurrentLocation(); HelperFunctions apiCallToRouting = new HelperFunctions(); //route option 1 routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag)); - timeEstimate[0] = estimateTime(routeSequences.get(0)); - estimateTolls(routeSequences.get(0)); + timeEstimate.add(estimateTime(routeSequences.get(0))); + tollsAmount.add(estimateTolls(routeSequences.get(0))); //route option 2 routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag)); - timeEstimate[1] = estimateTime(routeSequences.get(1)); - estimateTolls(routeSequences.get(1)); + timeEstimate.add(estimateTime(routeSequences.get(1))); + tollsAmount.add(estimateTolls(routeSequences.get(1))); //route option 3 routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag)); - timeEstimate[2] = estimateTime(routeSequences.get(2)); - estimateTolls(routeSequences.get(2)); + timeEstimate.add(estimateTime(routeSequences.get(2))); + tollsAmount.add(estimateTolls(routeSequences.get(2))); } public int enumRoutes() { - return routeSequences.length; + return routeSequences.size(); } public void selectRoute(int userSelection) { @@ -46,10 +47,10 @@ public class Route { public int getRouteSelected() {return routeSelected;} - public float estimateTolls(double[][] route) { + public float estimateTolls(Vector route) { float runningTolls = 0; - for (int i = 0; i <= route.length; i++) { - runningTolls += route[i][3]; + for (String[] el : route) { + runningTolls += Float.parseFloat(el[3]); } return runningTolls; } @@ -58,10 +59,15 @@ public class Route { //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 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) { runningTime += Double.parseDouble(el[1])/Double.parseDouble(el[2]); } 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;} }