import java.util.Scanner; public class SelfDrivingRoadtrip { public static void main(String[] args) { Vehicle myVehicle = new Vehicle(); Entertainment nowPlaying = new Entertainment(); Climate climate = new Climate(); Scanner userInput = new Scanner(System.in); int userSelection = -1; while (userSelection != 0) { userSelection = -1; System.out.print("\033[H\033[2J"); //Show current destination on main menu System.out.print("Current Destination: "); if (myVehicle.currentRoute.currentDestination.getDestinationAddress() != null) { System.out.print(myVehicle.currentRoute.currentDestination.getDestinationAddress() + "\n"); } else {System.out.print("None Selected\n");} //Show current route on main menu System.out.print("Current Route: "); if (myVehicle.currentRoute.getRouteSelected() == -1) { System.out.print("None Selected\n"); } else { String[] routes = myVehicle.currentRoute.enumRoutes(); String[] splitNames = routes[myVehicle.currentRoute.getRouteSelected()].split("\n"); System.out.print(splitNames[0] + "\n"); } //Show current fuel level on main menu System.out.printf("Fuel Level: %.0f%%\n", myVehicle.getFuelLevel()*100); //Show current media source on Main Menu System.out.print("Now Playing: " + nowPlaying.getMetadata() + "\n\n"); mainMenu(); userSelection = userInput.nextInt(); switch (userSelection) { case 1: //destination selection menu while (userSelection != 0) { destinationMenu(); userSelection = userInput.nextInt(); if (userSelection == 0) { userSelection = -1; break; } else if (userSelection == 1) { System.out.println("Destination 1 selected"); myVehicle.currentRoute.setRouteDestination("250 Community College Pkwy SE, Palm Bay, FL 32909"); userSelection = -1; HelperFunctions.sleep(3); break; } else { System.out.println("Please select a valid option."); userSelection = -1; HelperFunctions.sleep(3); } } break; case 2: //route selection menu if (myVehicle.currentRoute.currentDestination.getDestinationAddress() == null) { System.out.println("Please select a destination first."); userSelection = -1; break; } while (userSelection != 0) { routesMenu(myVehicle.currentRoute.enumRoutes()); userSelection = userInput.nextInt(); if (userSelection == 0) { userSelection = -1; break; } else if (userSelection <= myVehicle.currentRoute.countRoutesAvailable()) { myVehicle.currentRoute.selectRoute(userSelection - 1); System.out.println("Route " + userSelection + " selected"); userSelection = -1; HelperFunctions.sleep(3); break; } else { System.out.println("Please select a valid option."); userSelection = -1; HelperFunctions.sleep(3); } } break; case 3: //start navigation System.out.println("Start navigation"); myVehicle.run(); System.out.println("Navigation complete, destination reached."); HelperFunctions.pressEnterToContinue(); break; case 4: //entertainment controls while (userSelection != 0) { entertainmentMenu(); userSelection = userInput.nextInt(); if (userSelection == 0) { userSelection = -1; break; } else if (userSelection == 1) { nowPlaying.selectSource("RADIO", "FM 104.1"); userSelection = -1; break; } else if (userSelection == 2) { nowPlaying.selectSource("AUX", "AUX Input"); userSelection = -1; break; } else if (userSelection == 3) { nowPlaying.selectSource("BLUETOOTH", "Bluetooth Device"); userSelection = -1; break; } else { System.out.println("Please select a valid option"); userSelection = -1; } } break; case 5: //climate controls while (userSelection != 0) { climateMenu(); userSelection = -1; userSelection = userInput.nextInt(); if (userSelection == 0) { userSelection = -1; break; } else if (userSelection == 1) { userSelection = -1; climateTempMenu(climate.getCurrentTemps(), climate.getTargetTemps()); userSelection = userInput.nextInt(); if (userSelection == 0) { userSelection = -1; } else if (userSelection == 1) { System.out.print("Enter new left target temp (65-90F): "); climate.setTargetTemp(userInput.nextInt(), climate.getTargetTemps()[1]); } else if (userSelection == 2) { System.out.print("Enter new right target temp (65-90F): "); climate.setTargetTemp(climate.getTargetTemps()[0], userInput.nextInt()); } } else if (userSelection == 2) { userSelection = -1; climateFanMenu(climate.getFanSpeeds()); userSelection = userInput.nextInt(); if (userSelection == 0) { userSelection = -1; } else if (userSelection == 1) { userSelection = -1; climateFanSpeedMenu(); userSelection = userInput.nextInt(); climate.setFanSpeeds(Integer.toString(userSelection), climate.getFanSpeeds()[1]); } else if (userSelection == 2) { userSelection = -1; climateFanSpeedMenu(); userSelection = userInput.nextInt(); climate.setFanSpeeds(climate.getFanSpeeds()[0], Integer.toString(userSelection)); } } else if (userSelection == 3) { userSelection = -1; climate.run(); } } } } userInput.close(); } public static void mainMenu() { System.out.println("Main Menu\n=========\n"); System.out.println("1. Set Destination"); System.out.println("2. Select Route"); System.out.println("3. Start Navigation"); System.out.println("4. Entertainment Controls"); System.out.println("5. Climate Controls"); System.out.println("0. Turn Off"); System.out.print("\nSelection: "); } public static void destinationMenu() { System.out.print("\033[H\033[2J"); System.out.println("Destinations\n=============\n"); System.out.println("Select a Destination\n"); System.out.println("0. Go Back"); System.out.println("1. EFSC Palm Bay Campus\n 250 Community College Pkwy SE, Palm Bay, FL 32909"); System.out.print("\nSelection: "); } public static void routesMenu(String[] routes) { System.out.print("\033[H\033[2J"); System.out.println("Routes Available\n================\n"); System.out.println("Select a Route\n"); System.out.println("0. Go Back"); for (String el : routes) { System.out.println(el); } System.out.print("\nSelection: "); } public static void entertainmentMenu() { System.out.print("\033[H\033[2J"); System.out.println("Media\n=====\n"); System.out.println("Select a Source\n"); System.out.println("0. Go Back"); System.out.println("1. Radio"); System.out.println("2. AUX"); System.out.println("3. Bluetooth"); System.out.print("\nSelection: "); } public static void climateMenu() { System.out.print("\033[H\033[2J"); System.out.println("Climate Controls\n===============\n"); System.out.println("Select an option\n"); System.out.println("0. Go Back"); System.out.println("1. Set Temperature"); System.out.println("2. Set Fan Speed"); System.out.println("3. Run Climate Adjustments"); //only necessary while application is non-concurrent System.out.print("\nSelection: "); } public static void climateTempMenu(int[] currentTemps, int[] targetTemps) { System.out.print("\033[H\033[2J"); System.out.println("Temperature Controls\n===================\n"); System.out.println("Select an option\n"); System.out.println("0. Go Back"); System.out.println("1. Set Left Temperature | Current: " + currentTemps[0] + "; Set: " + targetTemps[0]); System.out.println("2. Set Right Temperature | Current: " + currentTemps[1] + "; Set: " + targetTemps[1]); System.out.print("\nSelection: "); } public static void climateFanMenu(String[] speeds) { System.out.print("\033[H\033[2J"); System.out.println("Fan Controls\n============\n"); System.out.println("Select an option\n"); System.out.println("0. Go Back"); System.out.println("1. Set Left Fan Speed | Current: " + speeds[0]); System.out.println("2. Set Right Fan Speed | Current: " + speeds[1]); System.out.print("\nSelection: "); } public static void climateFanSpeedMenu() { System.out.print("\033[H\033[2J"); System.out.println("Set Fan Speed\n=============\n"); System.out.println("Select an option\n"); System.out.println("0. Go Back"); System.out.println("1. OFF"); System.out.println("2. LOW"); System.out.println("3. MED"); System.out.println("4. HI"); System.out.print("\nSelection: "); } }