Пример #1
0
        private static void refuelingVehicle()
        {
            string licenceNumber;
            int    userChoice = 0;

            FuelEngine.eFuelTypes fuelType = 0;
            float litersToAdd = 0;

            Console.Write("Please enter vehicle licence number: ");
            licenceNumber = checkEmptyInput();
            Console.WriteLine(
                @"Now please choose the fuel type:
1. Soler
2. Octan95
3. Octan96
4. Octan98");
            userChoice = inputBetweenRange(1, 4);
            switch (userChoice)
            {
            case 1:
                fuelType = FuelEngine.eFuelTypes.Soler;
                break;

            case 2:
                fuelType = FuelEngine.eFuelTypes.Octan95;
                break;

            case 3:
                fuelType = FuelEngine.eFuelTypes.Octan96;
                break;

            case 4:
                fuelType = FuelEngine.eFuelTypes.Octan98;
                break;
            }

            Console.Write("Last thing, please enter how many liters you wish to add: ");
            litersToAdd = checkFloatParsing();
            try
            {
                m_Garage.refuelingVehicle(licenceNumber, fuelType, litersToAdd);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine(@"
This licence isn't exist in the garage.");
            }
            catch (ArgumentException i_ArgumentException)
            {
                Console.WriteLine(i_ArgumentException.Message);
            }
        }
Пример #2
0
        public void FuelTheVehicle(string i_LicensePlate, FuelEngine.eFuelTypes i_FuelType, float i_AmountToFill)
        {
            VehiclesInGarage vehicle = GetExistVehicles(i_LicensePlate);

            if (vehicle == null)
            {
                throw new ArgumentNullException();
            }

            if (!(vehicle.Vehicle.EnergySource is FuelEngine))
            {
                throw new ArgumentException();
            }

            (vehicle.Vehicle.EnergySource as FuelEngine).FuelOperation(i_AmountToFill, i_FuelType);
        }
Пример #3
0
        public void refuelingVehicle(string i_LicenceNumber, FuelEngine.eFuelTypes i_FuelType, float i_CapacityToAdd)
        {
            ArgumentException i_ArgumentException;

            if (m_VehiclesToFix.ContainsKey(i_LicenceNumber) == true)
            {
                if (m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.VehicleEngine is FuelEngine)
                {
                    if (((FuelEngine)m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.VehicleEngine).FuelType == i_FuelType)
                    {
                        if (m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.VehicleEngine.CurrentCapacity + i_CapacityToAdd <= m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.VehicleEngine.MaxCapacity)
                        {
                            ((FuelEngine)m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.VehicleEngine).RefuelingVehicle(i_CapacityToAdd, i_FuelType);
                        }
                        else
                        {
                            i_ArgumentException = new ArgumentException("The current capacity plus the capacity you entered excceed the max capacity.");
                            throw i_ArgumentException;
                        }
                    }
                    else
                    {
                        i_ArgumentException = new ArgumentException("The selected vehicle is driven by a different fuel type.");
                        throw i_ArgumentException;
                    }
                }
                else
                {
                    i_ArgumentException = new ArgumentException("The selected vehicle is driven by electricity.");
                    throw i_ArgumentException;
                }

                m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.EnergyToEmptyInPrecent = m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.VehicleEngine.CurrentCapacity / m_VehiclesToFix[i_LicenceNumber].VehicleOfOwner.VehicleEngine.MaxCapacity * 100;
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Пример #4
0
        public static void AddFuel()
        {
            Console.WriteLine("Please enter your license plate: ");
            string licensePlate = Console.ReadLine();

            if (licensePlate == null)
            {
                throw new ArgumentNullException();
            }

            bool isExistInGarage = IsVehicleExistInGarage(licensePlate);

            if (isExistInGarage)
            {
                FuelEngine.eFuelTypes fuelTypeChoosen =
                    (FuelEngine.eFuelTypes)EnumUserChoice(typeof(FuelEngine.eFuelTypes));

                Console.WriteLine("Please enter your amount of fuel to fill: ");
                string fuelAmount = Console.ReadLine();

                float fuelAmountFloat;
                bool  isSucceededToConvertUserChoice = float.TryParse(fuelAmount, out fuelAmountFloat);
                if (!isSucceededToConvertUserChoice)
                {
                    throw new FormatException();
                }

                fuelAmountFloat = Convert.ToInt32(fuelAmountFloat);
                m_Garage.FuelTheVehicle(licensePlate, fuelTypeChoosen, fuelAmountFloat);
                Console.WriteLine("Your vehicle was fuled successfuly.");
            }
            else
            {
                Console.WriteLine("Your vehicle is not in the garage! ");
            }
        }
Пример #5
0
        public void FuelOperation(float i_AddFuel, FuelEngine.eFuelTypes i_FuelType)
        {
            FuelEngine fuel = null;

            fuel.FuelOperation(i_AddFuel, m_FuelType);
        }