public void AddFuelToVehicle(string i_LicenseNumber, FuelEngine.eFuleType i_TypeFuelToFill, float i_AmountFuelToFill) { IsGarageEmpty(); if (!(r_Vehicles.ContainsKey(i_LicenseNumber))) { throw new Exception("We don't have this vehicle in our garage, sorry."); } Vehicle vehicle = r_Vehicles[i_LicenseNumber]; if (!(vehicle.Engine is FuelEngine)) { throw new Exception("This is not a Fuel driven Vehicle, please try again"); } (vehicle.Engine as FuelEngine).addFuel(i_AmountFuelToFill, i_TypeFuelToFill); }
private void addFuel() { if (!isGarageEmpty() && r_GarageLogic.NumberOfFuelVehicles > 0) { try { bool isValid = false; Console.WriteLine("choose one of the License numbers below: "); string o_LicenseNumber; do { printAllFuelVehicleLicense(); o_LicenseNumber = enterLicenseNumber(); Console.Clear(); isValid = r_GarageLogic.isFuelVehicle(o_LicenseNumber); if (!isValid) { Console.WriteLine("Not a valid License Number. Try again..."); } } while (isValid == false); Console.WriteLine( "Please enter the Type of Fuel to fill: 1 for Soler, 2 for Octan95, 3 for Octan96, or 4 for Octan98:"); string userInput = Console.ReadLine(); FuelEngine.eFuleType o_TypeFuelToFill = (FuelEngine.eFuleType)Enum.Parse(typeof(FuelEngine.eFuleType), userInput); Console.WriteLine("Please the amount to add in liters"); userInput = Console.ReadLine(); float o_AmountFuelToFill = float.Parse(userInput); r_GarageLogic.AddFuelToVehicle(o_LicenseNumber, o_TypeFuelToFill, o_AmountFuelToFill); Console.WriteLine("{0} Liter of {1} were successfully added To Vehicle No. {2}!", o_AmountFuelToFill, o_TypeFuelToFill.ToString(), o_LicenseNumber); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Please try again..."); addFuel(); } } else { Console.WriteLine("Garage is either empty or no Fuel driven Vehicles at the moment"); } }