private static void fillEnergyUI(string i_LicenseNumber, float i_AmountToFill, eEnergyType i_EnergyType) { bool tryAgain = true; while (tryAgain) { try { s_Garage.FllEnergy(i_LicenseNumber, i_AmountToFill, i_EnergyType); tryAgain = false; } catch (ValueOutOfRangeException e) { Console.WriteLine($"{e.Message}, must be between {e.MinValue} - {e.MaxValue}"); i_AmountToFill = GetInput.GetValidFloat(); } } }
private static void setWheelsUI(VehicleBuilder i_VehicleBeingBuilt, string i_WheelManufacturer, float i_CurrentAirPressure) { bool tryAgain = true; while (tryAgain) { try { i_VehicleBeingBuilt.SetWheels(i_WheelManufacturer, i_CurrentAirPressure); tryAgain = false; } catch (ValueOutOfRangeException e) { Console.WriteLine($"{e.Message}. The amount must be between {e.MinValue} to {e.MaxValue}. Try again"); i_CurrentAirPressure = GetInput.GetValidFloat(e.MinValue, e.MaxValue); } } }
private static void setEnergyUI(VehicleBuilder i_VehicleBeingBuilt, bool i_IsElectric, float i_CurrentEnergyLevel) { bool tryAgain = true; while (tryAgain) { try { i_VehicleBeingBuilt.SetEnergy(i_IsElectric, i_CurrentEnergyLevel); tryAgain = false; } catch (ValueOutOfRangeException e) { Console.WriteLine($"{e.Message}. The amount must be between {e.MinValue} to {e.MaxValue}. Try again"); i_CurrentEnergyLevel = GetInput.GetValidFloat(e.MinValue, e.MaxValue); } } }
// modes 5 and 6 public static void FillEnergy(bool i_IsElectric) { string licenseNumber = string.Empty; eEnergyType energyType = eEnergyType.Electric; float energyToFill = 0.0f; string getLicenseNumberMsg = @" In order to {0} the vehicle, please enter its license number:"; string getEnergyAmountMsg = @" Please enter the desired amount of {0} to fill ({1}):"; string successMsg = @" {0} vehicle number {1} is complete"; getLicenseNumberMsg = i_IsElectric ? string.Format(getLicenseNumberMsg, "charge") : string.Format(getLicenseNumberMsg, "refuel"); Console.WriteLine(getLicenseNumberMsg); licenseNumber = GetInput.GetLicenseNumber(false, out _); energyType = s_Garage.GetEnergyType(licenseNumber); if (i_IsElectric && energyType != eEnergyType.Electric) { Console.WriteLine($"vehicle no. {licenseNumber} can not be charged (is not electric)"); } else if (!i_IsElectric && energyType == eEnergyType.Electric) { Console.WriteLine($"vehicle no. {licenseNumber} can not be refueled (is electric)"); } else { getEnergyAmountMsg = i_IsElectric ? string.Format(getEnergyAmountMsg, energyType, "minutes for charging") : string.Format(getEnergyAmountMsg, energyType, "liters of gas"); Console.WriteLine(getEnergyAmountMsg); energyToFill = GetInput.GetValidFloat(); fillEnergyUI(licenseNumber, energyToFill, energyType); successMsg = string.Format(successMsg, energyType == eEnergyType.Electric ? "charging" : "refueling", licenseNumber); Console.WriteLine(successMsg); } }
// mode 1 internal static void AddVehicle() { string licenseNumber = string.Empty; string getLicenseNumberMsg = @" In order to add a new vehicle to the system, please enter its license number:"; Console.WriteLine(getLicenseNumberMsg); licenseNumber = GetInput.GetLicenseNumber(true, out bool isLicenseNumberRegistered); if (isLicenseNumberRegistered) { Console.WriteLine($"You changed vehicle number {licenseNumber} to 'inRepair' status"); s_Garage.ChangeStatusOfVehicle(licenseNumber, eStatus.InRepair); } else { eVehicleType vehicleType = eVehicleType.Car; string model = string.Empty; string nameOfOwner = string.Empty; string phoneNumOfOwner = string.Empty; bool isElectric = false; float currentEnergyLevel = 0.0f; float currentAirPressure = 0.0f; string wheelManufacturer = string.Empty; object[] uniqueFeatures = null; string getVehicleTypeMsg = @" Please pick a vehicle type: {0}"; getVehicleTypeMsg = string.Format(getVehicleTypeMsg, buildMenuFromEnum(typeof(eVehicleType))); string getModel = @" Please enter the vehicle's model:"; string getNameOfOwnerMsg = @" Please enter the vehicle's owner name (letters only):"; string getPhoneNumOfOwnerMsg = @" Please enter the owner's phone number (digits only):"; string getIsElectricMsg = @" Is the vehicle electric? (yes / no)"; string getCurrentEnergyLevelMsg = @" Please enter the current amount of {0}:"; string getCurrentAirPressureMsg = @" Please enter the current air pressure:"; string getWheelManufacturerMsg = @" Please enter the wheels manufacturer:"; string uniqueFeatureMsg = @" Please enter {0}, possible values are: {1}"; string successMsg = @" Registration complete!"; string failsMsg = @" Registration could not be completed missing data"; Console.WriteLine(getVehicleTypeMsg); vehicleType = GetInput.GetVehicleType(); Console.WriteLine(getModel); model = GetInput.GetValidString(false, false); Console.WriteLine(getNameOfOwnerMsg); nameOfOwner = GetInput.GetValidString(false, true); Console.WriteLine(getPhoneNumOfOwnerMsg); phoneNumOfOwner = GetInput.GetValidString(true, false); VehicleBuilder newVehicle = s_Garage.BuildVehicle(vehicleType, model, licenseNumber, nameOfOwner, phoneNumOfOwner); if (newVehicle.CanBeElectric()) { Console.WriteLine(getIsElectricMsg); isElectric = GetInput.GetIsElectricOrNot(); } getCurrentEnergyLevelMsg = string.Format(getCurrentEnergyLevelMsg, isElectric ? "battery" : "gas"); Console.WriteLine(getCurrentEnergyLevelMsg); currentEnergyLevel = GetInput.GetValidFloat(); setEnergyUI(newVehicle, isElectric, currentEnergyLevel); Console.WriteLine(getWheelManufacturerMsg); wheelManufacturer = GetInput.GetValidString(false, false); Console.WriteLine(getCurrentAirPressureMsg); currentAirPressure = GetInput.GetValidFloat(); setWheelsUI(newVehicle, wheelManufacturer, currentAirPressure); uniqueFeatures = GetInput.GetUniqueFeatures(uniqueFeatureMsg, newVehicle); newVehicle.SetUniqueFeatures(uniqueFeatures); if (s_Garage.TryAddVehicle(newVehicle, licenseNumber)) { Console.WriteLine(successMsg); } else { Console.Out.WriteLine(failsMsg); } } }