private void chargeElectricVehicleUI() { string plateNumber = getStringFromUser(Strings.enter_plate_number); float amountOfElectricInMinutesToAdd = getFloatFromUser(Strings.amount_to_charge); try { BaseVehicle VehicleToCharge = m_Garage.GetVehicleByPlateNumber(plateNumber).Vehicle; m_Garage.ChargeElectricVehicle(VehicleToCharge, amountOfElectricInMinutesToAdd); } catch (ValueOutOfRangeException i_ValueOutOfRange) { showError(i_ValueOutOfRange.Message); if (amountOfElectricInMinutesToAdd > i_ValueOutOfRange.MaxValue) { showError(string.Format(Strings.out_of_range_max, amountOfElectricInMinutesToAdd)); } else { showError(string.Format(Strings.out_of_range_min, amountOfElectricInMinutesToAdd)); } } catch (Exception i_PlateError) { showError(i_PlateError.Message); } }
private bool chargeAVehicle() { bool isVehicleExists = false; bool isSuccessfullOperation = false; string licenseNumber = getLicenseNumber(); isVehicleExists = r_GarageManager.IsVehicleExists(licenseNumber); if (isVehicleExists == false) { Console.WriteLine("Vehicle does not exist in the garage."); } else { Console.WriteLine("Please enter the amount of minutes to charge:"); bool isIllegalOperation = false; while (isIllegalOperation == false && isSuccessfullOperation == false) { float amountOfMinutesToCharge = readFloatFromConsole(); try { r_GarageManager.ChargeElectricVehicle(licenseNumber, amountOfMinutesToCharge); isSuccessfullOperation = true; } catch (ArgumentException) { Console.WriteLine("The vehicle is not an electric based vehicle."); isIllegalOperation = true; } catch (ValueOutOfRangeException voore) { Console.WriteLine(voore.ToString()); } catch (Exception e) { // handle battery is full exception Console.WriteLine(e.Message); isIllegalOperation = true; } } } return(isSuccessfullOperation); }