import java.io.*;
public class vehicleDriver
{
public static void main(String[]args)
{
vehicle myVehicle = new vehicle();
processMenu(myVehicle.vehicle());
}
public static void displayMenu()
{
System.out.println("Please type your menu choice and press enter.\n");
System.out.println("0. Display Current Vehcile Attributes.\n");
System.out.println("1. Enter Vehicle Make.\n");
System.out.println("2. Enter Vehcile Model.\n");
System.out.println("3. Enter Vehcile Color.\n");
System.out.println("4. Enter Number of Doors.\n");
System.out.println("5. Enter Number of Cylinders in the Engine.\n");
System.out.println("6. Enter Current Speed.\n");
System.out.println("7. Enter To Stop Vehicle.\n");
System.out.println("8. Enter To Speed Vehicle Up.\n");
System.out.println("9. Enter To Slow Vehicle Down.\n");
System.out.println("10. Enter To Open Doors.\n");
System.out.println("11. Enter To Close Doors.\n");
System.out.println("99. Enter To Quit Vehicle Application.\n");
}
public static void DoorConfig(boolean[] isDoorOpen, int doors)
{
for(int i = 0;i < doors; i++)
{
if(isDoorOpen[i] = false)
System.out.println("Door is Closed.");
else
System.out.println("Door is Open.");
}
}
//Create BufferedReader for keyboard input
private static BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ));
public static void processMenu(vehicle myVehicle) throws IOException
{
//Declare variables
boolean isDoorOpen[] = new boolean[10];
String input = "";
int number = 0;
int choice = 0;
//Set doors to closed by default
for(int i = 0; i < isDoorOpen.length; i++)
isDoorOpen[i] = false;
//Loop through menu until quit is chosen
while(choice != 99)
{
displayMenu();
System.out.println("Enter menu option now: ");
input = stdin.readLine();
choice = Integer.parseInt( input );
switch(choice)
{
case 0: System.out.println("The Vehicl Attributes are:");
System.out.println("\nMake: " + myVehicle.get_vehicleMake());
System.out.println("\nModel: " + myVehicle.get_vehicleModel());
System.out.println("\nColor: " + myVehicle.get_vehicleColor());
System.out.println("\n#Doors: " + myVehicle.get_vehicleNumOfDoors());
System.out.println("\n#Cylinders: " + myVehicle.get_vehicleNumOfCylinders());
System.out.println("\nSpeed: " + myVehicle.get_vehicleSpeed() + "\n");
DoorConfig(isDoorOpen, myVehicle.get_vehicleNumOfDoors());
break;
case 1: System.out.println("Enter a new make: ");
input = stdin.readLine();
myVehicle.set_vehicleMake(input);
System.out.print("Vehicle's make is now " + myVehicle.get_vehicleMake() + "\n");
break;
case 2: System.out.println("Enter a new model: ");
input = stdin.readLine();
myVehicle.set_vehicleModel(input);
System.out.print("Vehicle's model is now " + myVehicle.get_vehicleModel() + "\n");
break;
case 3: System.out.println("Enter a new color: ");
input = stdin.readLine();
myVehicle.set_vehicleColor(input);
System.out.print("Vehicle's new color is " + myVehicle.get_vehicleColor() + "\n");
break;
case 4: System.out.println("Enter a number of doors: ");
input = stdin.readLine();
number = Integer.parseInt( input );
myVehicle.set_vehicleNumOfDoors(number);
System.out.print("Vehicle now has " + myVehicle.get_vehicleNumOfDoors() + " doors\n");
break;
case 5: System.out.println("Enter a number of cylinders: ");
input = stdin.readLine();
number = Integer.parseInt( input );
myVehicle.set_vehicleNumOfCylinders(number);
System.out.print("Vehicle now has " + myVehicle.get_vehicleNumOfCylinders() + " cylinders\n");
case 6: System.out.println("Enter number for current speed: ");
input = stdin.readLine();
number = Integer.parseInt( input );
myVehicle.set_vehicleSpeed(number);
System.out.print("You are now going " + myVehicle.get_vehicleSpeed() + "mph\n");
break;
case 7: System.out.println("Stopping vehicle, You will be slowing down by 1 mph\n");
number = myVehicle.vehicleStop();
System.out.println("Vehicle has stopped after slowing down from " + number + "mph\n");
System.out.print("Current speed is: " + myVehicle.get_vehicleSpeed() + "mph\n");
break;
case 8: System.out.println("Enter how fast you want to go: ");
input = stdin.readLine();
number = Integer.parseInt( input );
System.out.print(myVehicle.get_vehicleModel() + " current speed is " + myVehicle.get_vehicleSpeed() + "\n");
int temp = myVehicle.vehicleAccelerate(number, isDoorOpen);
System.out.print("Vehicle sped up to " + myVehicle.get_vehicleSpeed() + " after accelerating "+temp+"mph\n");
break;
case 9: System.out.println("Enter how much you would like to slow down to: ");
input = stdin.readLine();
number = Integer.parseInt( input);
System.out.print(myVehicle.get_vehicleModel() + " current speed is " + myVehicle.get_vehicleSpeed() + " mph\n");
temp = myVehicle.vehicleSlowDown(number);
System.out.print("Vehicle slowed down to " + myVehicle.get_vehicleSpeed() + " after slowing down " +temp+" mph\n");
break;
case 10: System.out.println("Enter a door number you want to open: ");
input = stdin.readLine();
number = Integer.parseInt( input );
System.out.print("Doors open or closed before opening chosen door\n");
DoorConfig(isDoorOpen, myVehicle.get_vehicleNumOfDoors());
isDoorOpen = myVehicle.door_open( number, isDoorOpen);
System.out.println("\nDoors open or closed after opening chosen door\n");
DoorConfig(isDoorOpen, myVehicle.get_vehicleNumOfDoors());
break;
case 11: System.out.println("Enter door number you would like to close: ");
input = stdin.readLine();
number = Integer.parseInt( input );
System.out.print("Doors open orclosed before closing chosen door\n");
DoorConfig(isDoorOpen, myVehicle.get_vehicleNumOfDoors());
isDoorOpen = myVehicle.door_closed(number, isDoorOpen);
System.out.print("\nDoors open or closed after closing chosen door\n");
DoorConfig(isDoorOpen, myVehicle.get_vehicleNumOfDoors());
break;
case 99: System.out.println("\nQuit opting was chosen, quitting vehicle application, please wait\n");
break;
default: System.out.println("incorrect value, Enter only available menu options.");
}//end of switch case\\
}//end of while loop\\
}
}
2007-12-11
04:11:04
·
1 answers
·
asked by
mattjcook07
2
in
Programming & Design