diff --git a/DrivingRoute.txt b/DrivingRoute.txt new file mode 100644 index 0000000..5598ae5 --- /dev/null +++ b/DrivingRoute.txt @@ -0,0 +1,12 @@ +FWD;0.2;20 +LEFT;0.044;20 +LEFT;0.1;35 +LEFT;3.0;45 +RIGHT;2.3;50 +LEFT;0.3;50 +FWD;9.6;70 +RIGHT;0.3;50 +RIGHT;0.2;35 +LEFT;0.2;35 +LEFT;0.4;35 +RIGHT;0.08;20 diff --git a/HelperFunctions.java b/HelperFunctions.java index a663b2c..365e585 100644 --- a/HelperFunctions.java +++ b/HelperFunctions.java @@ -1,3 +1,8 @@ +import java.util.Vector; +import java.nio.file.Paths; +import java.util.Scanner; +import java.io.IOException; + //a collection of helper functions to act as responses for otherwise //external calls in this implementation for demo purposes @@ -18,35 +23,25 @@ public class HelperFunctions { return returnArray; } - public double[][] routingAPI(double[] startCoords, double[] destinationCoords, Boolean tollsFlag, Boolean hwyFlag) { - //ideally this would return a series of coordinates, but for the sake of the demo it's just - //going to concatenate the start and end into a 2x2 array with just those two steps - //speed is also returned in MPH for the expected points as the third index in the array's second dimension - double[][] routeArray = new double[2][3]; + public Object[] routingAPI(double[] startCoords, double[] destinationCoords, Boolean tollsFlag, Boolean hwyFlag) { + //method simulates a call to translate two pairs of coords into a driving route + //for demo purposes returns a pregenerated set of move instructions + //located in DrivingRoute.txt as semicolon delimited strings for direction, distance, and speedLimit + Vector routeArray = new Vector(); if (tollsFlag && hwyFlag) { //provides a result that both avoid tolls and major highways - routeArray[0] = startCoords; - routeArray[1] = destinationCoords; - routeArray[0][2] = 45; //avg speed leg 1 - routeArray[0][3] = 0; //tolls leg 1 - routeArray[1][2] = 45; //avg speed leg 2 - routeArray[1][3] = 0; //tolls leg 2 } else if (tollsFlag && !hwyFlag) { //provides a result that avoids tolls but not major highways - routeArray[0][2] = 60; //avg speed leg 1 - routeArray[0][3] = 0; //tolls leg 1 - routeArray[1][2] = 45; //avg speed leg 2 - routeArray[1][3] = 0; //tolls leg 2 } else if (!tollsFlag && hwyFlag) { //provides a result that does not avoid tolls and does avoid major highways - routeArray[0][2] = 45; //avg speed leg 1 - routeArray[0][3] = 1.50; //tolls leg 1 - routeArray[1][2] = 45; //avg speed leg 2 - routeArray[1][3] = 0; //tolls leg 2 } else if (!tollsFlag && !hwyFlag) { //provides a result that does not avoid tolls or major highways - routeArray[0][2] = 60; //avg speed leg 1 - routeArray[0][3] = 1.50; //tolls leg 1 - routeArray[1][2] = 45; //avg speed leg 2 - routeArray[1][3] = 0; //tolls leg 2 + try (Scanner infile = new Scanner(Paths.get("DrivingRoute.txt"))) { + while (infile.hasNext()) { + routeArray.addElement(infile.nextLine().split(";")); + } + } catch (IOException e) { + System.err.println("File handling error"); + } + } - return routeArray; + return routeArray.toArray(); } public int[] internalTempSensors() {