import java.util.Vector; import java.nio.file.Paths; import java.util.Scanner; import java.io.IOException; import java.util.concurrent.*; //a collection of helper functions to act as responses for otherwise //external calls in this implementation for demo purposes public class HelperFunctions { public double[] geocodingAPI(String inputAddress) { //simulates converting an input address into lat-long coordinates double[] coords = new double[2]; switch (inputAddress) { case "250 Community College Pkwy SE, Palm Bay, FL 32909": coords[0] = 27.993699393377653; coords[1] = -80.63006489971767; break; case "3865 N Wickham Rd, Melbourne, FL 32935": coords[0] = 28.17009584609403; coords[1] = -80.67083038806463; break; } double[] returnArray = coords; return returnArray; } public Vector routingAPI(double[] startCoords, String destinationAddress, 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 try (Scanner infile = new Scanner(Paths.get("DrivingRoute2.txt"))) { while (infile.hasNext()) { routeArray.addElement(infile.nextLine().split(";")); } } catch (IOException e) { System.err.println("File handling error"); } } else if (tollsFlag && !hwyFlag) { //provides a result that avoids tolls but not major highways try (Scanner infile = new Scanner(Paths.get("DrivingRoute1.txt"))) { while (infile.hasNext()) { routeArray.addElement(infile.nextLine().split(";")); } } catch (IOException e) { System.err.println("File handling error"); } } else if (!tollsFlag && hwyFlag) { //provides a result that does not avoid tolls and does avoid major highways try (Scanner infile = new Scanner(Paths.get("DrivingRoute2.txt"))) { while (infile.hasNext()) { routeArray.addElement(infile.nextLine().split(";")); } } catch (IOException e) { System.err.println("File handling error"); } } else if (!tollsFlag && !hwyFlag) { //provides a result that does not avoid tolls or major highways try (Scanner infile = new Scanner(Paths.get("DrivingRoute1.txt"))) { while (infile.hasNext()) { routeArray.addElement(infile.nextLine().split(";")); } } catch (IOException e) { System.err.println("File handling error"); } } return routeArray; } public int[] internalTempSensors() { int[] temps = {76, 74}; return temps; } public int externalTempSensors() { return 88; } public static void sleep(int time) { //helper function to sleep 1 second try {TimeUnit.SECONDS.sleep(time);} //sleep for 1-15 second to simulate traffic light catch (InterruptedException e) {System.err.println("Sleep interrupted");} } public static void pressEnterToContinue() { System.out.println("Press Enter key to continue..."); try { System.in.read(); } catch(Exception e) {} } }