コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Garage.cs プロジェクト: galdil/Garage-Management
        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();
        }