internal void ShowVehiclesWithFilter() { VehicleGarageInfo.eVehicleCondition vehicleCondition; while (true) { try { vehicleCondition = (VehicleGarageInfo.eVehicleCondition)InputValidation.EnumChoiseToInt(typeof(VehicleGarageInfo.eVehicleCondition), UserConsole.ChooseString("vehicle condition")); UserConsole.Print(string.Format("All vehicles in the garage that are {0}:", vehicleCondition.ToString())); UserConsole.Print(r_Garage.VehicleInGarageToString(vehicleCondition)); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } finally { UserConsole.PrintAndRead("Press any key to go back to vehicle menu"); endAction(); } } endAction(); }
internal void AddVehicleToGarage() { Vehicle vehicle; VehicleCreater.eVehicleTypes vehicleType; while (true) { try { vehicleType = (VehicleCreater.eVehicleTypes)InputValidation.EnumChoiseToInt(typeof(VehicleCreater.eVehicleTypes), UserConsole.ChooseString("vehicle type")); vehicle = VehicleCreater.InitVehicle(vehicleType); vehicle.LicenseNumber = InputValidation.GetString("\nEnter License number: "); vehicle.ModelName = InputValidation.GetString("\nEnter model Name: "); r_Garage.AddVehicleToGarage(vehicle); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } vehicle.VehicleInfo = setVehicleInfo(); setEnergy(vehicle); UserConsole.SleepAndClear(); setWheelInfo(vehicle); UserConsole.Print("\n"); setExtraDeatails(vehicle); UserConsole.Print("\nVehicle was added successfully!"); endAction(); }
private void setWheelInfo(Vehicle i_Vehicle) { float airInput; string wheelManufacture; while (true) { try { wheelManufacture = InputValidation.GetString("\nEnter wheel manufacture: "); airInput = InputValidation.GetFloat("\nEnter how much air you want to add to the wheels: "); foreach (Wheel wheel in i_Vehicle.Wheels) { wheel.InflateWheel(airInput); wheel.ManufacturerName = wheelManufacture; } break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } }
public static int GetPositiveInt(string i_Msg) { string stringInput; UserConsole.Print(i_Msg); stringInput = UserConsole.Read(); return(parseInt(stringInput)); }
public static string GetString(string i_Msg) { string stringInput; UserConsole.Print(i_Msg); stringInput = UserConsole.Read(); if (stringInput.Length == 0) { throw new Exception("Please enter a string"); } else { return(stringInput); } }
private void setCarInfo(Car i_Car) { while (true) { try { i_Car.Color = (Car.eColor)InputValidation.EnumChoiseToInt(typeof(Car.eColor), UserConsole.ChooseString("car color")); i_Car.NumberOfDoors = (Car.eNumberOfDoors)InputValidation.EnumChoiseToInt(typeof(Car.eNumberOfDoors), UserConsole.ChooseString("number of doors for car")); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } }
private void setTruckInfo(Truck i_Truck) { while (true) { try { i_Truck.ContainsDangerousMaterials = InputValidation.GetBool("\nDoes truck contains dangerous materials? "); i_Truck.MaxCarryWeight = InputValidation.GetFloat("\nEnter max carry weight: "); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } }
private void setMotorcycleInfo(Motorcycle i_Motorcycle) { while (true) { try { i_Motorcycle.LicenseType = (Motorcycle.eLicenseType)InputValidation.EnumChoiseToInt(typeof(Motorcycle.eLicenseType), UserConsole.ChooseString("license type")); i_Motorcycle.EngineVolume = InputValidation.GetPositiveInt("\nEnter Engine volume: "); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } }
public static string GetStringNumber(string i_Msg) { string stringInput; bool isNumber; int number = 0; UserConsole.Print(i_Msg); stringInput = UserConsole.Read(); isNumber = int.TryParse(stringInput, out number); if (!isNumber || number < 0) { throw new ArgumentException("The input is not a number"); } return(stringInput); }
internal void ShowAllVehicles() { try { UserConsole.Print("All vehicals in the garage: \n"); UserConsole.Print(r_Garage.VehicleInGarageToString()); } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } finally { UserConsole.PrintAndRead("Press any key to go back to vehicle menu"); endAction(); } }
internal void FillAirWheels() { while (true) { try { r_Garage.FillAirToMax(r_Vehicle.LicenseNumber); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } UserConsole.Print("Filling air finished!"); endAction(); }
internal void ChangeVehicleStatus() { while (true) { try { VehicleGarageInfo.eVehicleCondition vehicleStatus = (VehicleGarageInfo.eVehicleCondition)InputValidation.EnumChoiseToInt(typeof(VehicleGarageInfo.eVehicleCondition), UserConsole.ChooseString("vehicle condition")); r_Garage.ChangeVehicleCondition(r_Vehicle.LicenseNumber, vehicleStatus); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } endAction(); }
public static void NextStepMainMenu(Garage i_Garage) { UserConsole outputUser = new UserConsole(); GarageAction garageAction = new GarageAction(i_Garage); int userChoise; UserConsole.MainMenu(); while (true) { try { userChoise = InputValidation.GetInt(string.Empty, 1, 5); break; } catch (Exception ex) { UserConsole.Print(ex.Message); } } UserConsole.SleepAndClear(); switch (userChoise) { case 1: garageAction.AddVehicleToGarage(); break; case 2: garageAction.ShowAllVehicles(); break; case 3: garageAction.ShowVehiclesWithFilter(); break; case 4: NextStepVehicleMenu(i_Garage, null); break; case 5: System.Environment.Exit(0); break; } }
public static bool GetBool(string i_Msg) { string inputString; bool result = true; UserConsole.Print(i_Msg); UserConsole.Print("Enter 0 for no, 1 for yes."); inputString = UserConsole.Read(); if (!inputString.Equals("1") && !inputString.Equals("0")) { throw new Exception("You didnt enter 0 or 1"); } else if (inputString.Equals("0")) { result = false; } return(result); }
private VehicleGarageInfo setVehicleInfo() { VehicleGarageInfo vehicleGarageInfo; while (true) { try { string ownerName = InputValidation.GetString("\nEnter owner Name: "); string ownerNumber = InputValidation.GetStringNumber("\nEnter owner phone number: "); vehicleGarageInfo = new VehicleGarageInfo(ownerName, ownerNumber); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } return(vehicleGarageInfo); }
internal void FillElectricVehicle() { while (true) { try { float amountOfEnergy = InputValidation.GetFloat("Enter the amount of minutes of energy to add"); r_Garage.FillEnergeVehicle(r_Vehicle.LicenseNumber, amountOfEnergy); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); if (ex.Message.Contains("on fuel")) { break; } } } endAction(); }
public static float GetFloat(string i_Msg) { string stringInput; float o_InputNumber = 0; bool isNumber; UserConsole.Print(i_Msg); stringInput = UserConsole.Read(); isNumber = float.TryParse(stringInput, out o_InputNumber); if (!isNumber) { throw new FormatException("The input is not a number"); } else if (o_InputNumber < 0) { throw new Exception("The input is not a positive number"); } else { return(o_InputNumber); } }
private float setElectric(Vehicle i_Vehicle) { float energyAmount = 0; while (true) { try { ElectricEngine ElectricEngine = i_Vehicle.Engine as ElectricEngine; UserConsole.SleepAndClear(); energyAmount = InputValidation.GetFloat("\nEnter amount of minutes of energy you want to fill: "); ElectricEngine.FillEnergy(energyAmount); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } return(energyAmount); }
internal void FillFuelVehicle() { while (true) { try { FuelEngine.eFuelType fuelTypeInput = (FuelEngine.eFuelType)InputValidation.EnumChoiseToInt(typeof(FuelEngine.eFuelType), UserConsole.ChooseString("fuel type")); float amountOfFuel = InputValidation.GetFloat("Enter the amount of fuel to fill"); r_Garage.FillFuelVehicle(r_Vehicle.LicenseNumber, fuelTypeInput, amountOfFuel); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); if (ex.Message.Contains("not on fuel!")) { break; } } } endAction(); }
public static int EnumChoiseToInt(Type i_EnumType, string i_msg) { string userInput; string msg; int userChoise; int minChoise = 1; int maxChoise; UserConsole.SleepAndClear(); UserConsole.Print(i_msg); UserConsole.Print(UserConsole.EnumToString(i_EnumType)); userInput = UserConsole.Read(); userChoise = parseInt(userInput); maxChoise = Enum.GetNames(i_EnumType).Length; if ((userChoise < minChoise) || (userChoise > maxChoise)) { throw new ValueOutOfRangeException((float)minChoise, (float)maxChoise); } msg = string.Format(@"You choose {0}", userChoise); UserConsole.Print(msg); return(userChoise); }
private float setFuel(Vehicle i_Vehicle) { FuelEngine.eFuelType fuelType; float fuelAmount = 0; while (true) { try { FuelEngine fuelEngine = i_Vehicle.Engine as FuelEngine; UserConsole.Print("\nLets fill up Fuel!"); fuelType = (FuelEngine.eFuelType)InputValidation.EnumChoiseToInt(typeof(FuelEngine.eFuelType), UserConsole.ChooseString("fuel type")); fuelAmount = InputValidation.GetFloat("\nEnter amount of fuel you want to fill: "); fuelEngine.FillFuel(fuelType, fuelAmount); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } return(fuelAmount); }
internal void VehicleInfo() { UserConsole.Print(r_Garage.VehicleInfo(r_Vehicle.LicenseNumber)); UserConsole.PrintAndRead("\nPress any key to go back to vehicle menu"); endAction(); }
private void endAction() { UserConsole.SleepAndClear(); MenuToUser.NextStepMainMenu(r_Garage); }
private void endAction() { UserConsole.SleepAndClear(); MenuToUser.NextStepVehicleMenu(r_Garage, r_Vehicle); }
public static void NextStepVehicleMenu(Garage i_Garage, Vehicle i_Vehicle) { UserConsole outputUser = new UserConsole(); int userChoise; string licenseNumber; Vehicle vehicle; VehicleAction vehicleAction = null; bool inputAnswer = true; if (i_Vehicle != null) { while (true) { try { inputAnswer = InputValidation.GetBool("Do you want to switch vehicle?"); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } if (!inputAnswer) { vehicleAction = new VehicleAction(i_Vehicle, i_Garage); } } if (inputAnswer) { while (true) { try { licenseNumber = InputValidation.GetString("Enter License number"); vehicle = i_Garage.GetVehicle(licenseNumber); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } vehicleAction = new VehicleAction(vehicle, i_Garage); } while (true) { try { UserConsole.VehicleMenu(); userChoise = InputValidation.GetInt(string.Empty, 1, 6); break; } catch (Exception ex) { UserConsole.ExceptionOutput(ex); } } UserConsole.SleepAndClear(); switch (userChoise) { case 1: vehicleAction.ChangeVehicleStatus(); break; case 2: vehicleAction.FillAirWheels(); break; case 3: vehicleAction.FillFuelVehicle(); break; case 4: vehicleAction.FillElectricVehicle(); break; case 5: vehicleAction.VehicleInfo(); break; case 6: NextStepMainMenu(i_Garage); break; } }
internal void StartGarageApp() { UserConsole.Print("\n\t\t\t░W░e░l░c░o░m░e░ ░t░o░ ░t░h░e░ ░G░A░R░A░G░E░\n"); MenuToUser.NextStepMainMenu(r_Garage); }