示例#1
0
        private void refuelGasVehicleInGarage()
        {
            Console.Clear();
            bool   isInvalidRefuelInput = true;
            string licensePlate         = licensePlateInput();

            GasEngine.eFuelType fuelTypeToGas = printMenuFormatAndReturnUserChoice <GasEngine.eFuelType>("Choose fuel type:");
            float fuelAmount;

            while (isInvalidRefuelInput)
            {
                try
                {
                    fuelAmount = garagePositiveFloatVaribalesInput("Enter amount of fuel to add:");

                    m_GarageModel.RefuelGasVehicle(licensePlate, fuelTypeToGas, fuelAmount);
                    isInvalidRefuelInput = false;
                    Console.WriteLine("Vehicle successfully refueld.");
                    System.Threading.Thread.Sleep(2500);
                }
                catch (ValueOutOfRangeException outOfRangeException)
                {
                    Console.WriteLine(string.Format("{0} (Range: {1} - {2})", outOfRangeException.Message, outOfRangeException.MinValue, outOfRangeException.MaxValue));
                }
            }
        }
示例#2
0
        public void RefuelGasVehicle(string i_LicensePlate, GasEngine.eFuelType i_FuelType, float i_AmountOfFuelToAdd)
        {
            VehicleInGarage vehicleInGarageToUpdate = FindAndReturnVehicleInGarage(i_LicensePlate);

            if (vehicleInGarageToUpdate.Vehicle.Engine is GasEngine)
            {
                ((GasEngine)vehicleInGarageToUpdate.Vehicle.Engine).Refueling(i_AmountOfFuelToAdd, i_FuelType);
                vehicleInGarageToUpdate.Vehicle.UpdateEnergyPercentage();
            }
            else
            {
                throw new ArgumentException("This is not a fuel based vehicle.");
            }
        }