public void RefuelVehicle(string i_License, string i_TypeOfFuel, string i_AmountToFuel) { Vehicle vehicleToRefuel; float amountToFuel; Fuel.FuelType fuelType = (Fuel.FuelType)Enum.Parse(typeof(Fuel.FuelType), i_TypeOfFuel); if (!CheckIfInGarage(i_License)) { throw new ArgumentException(); } bool validFormat = float.TryParse(i_AmountToFuel, out amountToFuel); if (!validFormat) { throw new FormatException(); } m_VehiclesInTheGarage.TryGetValue(i_License, out vehicleToRefuel); ((vehicleToRefuel.SourceOfEnergy) as Fuel).Refuel(amountToFuel, fuelType); }
public void RefuelVehicle(string i_License, string i_TypeOfFuel, string i_AmountToFuel) { Vehicle vehicleToRefuel; float amountToFuel, newFuelAMount; Fuel.FuelType fuelType = (Fuel.FuelType)Enum.Parse(typeof(Fuel.FuelType), i_TypeOfFuel); if (!CheckIfInGarage(i_License)) { throw new ArgumentException(); } bool validFormat = float.TryParse(i_AmountToFuel, out amountToFuel); if (!validFormat) { throw new FormatException(); } m_VehiclesInTheGarage.TryGetValue(i_License, out vehicleToRefuel); newFuelAMount = ((vehicleToRefuel.SourceOfEnergy) as Fuel).Refuel(amountToFuel, fuelType); vehicleToRefuel.VehicleDictionary["Current fuel amount"] = newFuelAMount.ToString(); vehicleToRefuel.VehicleDictionary["Percentage of energy left in vehicle"] = vehicleToRefuel.SourceOfEnergy.EnergyPercentageCalculator().ToString(); }