Ejemplo n.º 1
0
 public GasEngine(eGasType i_GasType, float i_MaximumAmoutOfEnergyToCharge, float i_AmountOfEnergyLeft)
 {
     m_GasType = i_GasType;
     m_MaximumAmountOfEnergy = i_MaximumAmoutOfEnergyToCharge;
     ValidateEnergyValues(i_AmountOfEnergyLeft);
     AmountOfEnergyLeft = i_AmountOfEnergyLeft;
 }
Ejemplo n.º 2
0
        // 5 Method- The method refuel vehicle on gas
        public void Refuel(string i_LicenseNumber, eGasType i_FuelType, float i_FuelToAdd)
        {
            GarageCustomer customer = FindVehicleInGarage(i_LicenseNumber);
            GasTank        gasTank  = customer.Vehicle.GasTank;


            if (gasTank != null)
            {
                if (!gasTank.GasType.ToString().Equals(i_FuelType.ToString()))
                {
                    throw new ArgumentException("Wrong fuel type"); // throw wrong gas exception.
                }

                else
                {
                    if (i_FuelToAdd < 0 || i_FuelToAdd > gasTank.MaxCapacity - gasTank.CurrentAmount)
                    {
                        throw new ValueOutOfRangeException(gasTank.MaxCapacity - gasTank.CurrentAmount, 0);
                    }

                    else
                    {
                        gasTank.CurrentAmount      += i_FuelToAdd;
                        customer.Vehicle.EnergyLeft = gasTank.CurrentAmount / gasTank.MaxCapacity;
                    }
                }
            }
            else
            {
                throw new ArgumentException("Cannot refuel with gas an electric vehicle");
            }
        }
Ejemplo n.º 3
0
        private static void fillGasInVehicle()
        {
            string licenseNumber = ConsoleUI.GetField("License Number: ", !v_LettersNumbersOnly, v_NumbersOnly);

            ConsoleUI.CreateEnumArray <eGasType>();
            string   gasType     = ConsoleUI.GetField("Gas Type: ", !v_LettersNumbersOnly, v_NumbersOnly);
            eGasType gasTypeEnum = ConsoleUI.ParseEnum <eGasType>(gasType);
            float    gasAmount   = ConsoleUI.ConvertToFloat(ConsoleUI.GetUserInput("Amount: "));

            try
            {
                Garage.FuelVehicle(licenseNumber, gasTypeEnum, gasAmount);
                ConsoleUI.PrintToScreen("SUCCESS: Gas was filled successfully");
            }
            catch (ArgumentException ex)
            {
                ConsoleUI.PrintToScreen(string.Format("ERROR: {0}{1}Try again or press {2} to go back to the menu", ex.Message, Environment.NewLine, ConsoleUI.Quit));
                fillGasInVehicle();
            }
            catch (ValueOutOfRangeException ex)
            {
                ConsoleUI.PrintToScreen(string.Format("{0}{1}Try again or press {2} to go back to the menu", ex.Message, Environment.NewLine, ConsoleUI.Quit));
                fillGasInVehicle();
            }
            catch
            {
                ConsoleUI.PrintToScreen(string.Format("ERROR: An error occured...{0}Try again or press {1} to go back to the menu", Environment.NewLine, ConsoleUI.Quit));
                fillGasInVehicle();
            }
        }
Ejemplo n.º 4
0
 public void CheckGasType(eGasType i_GasType)
 {
     if (i_GasType != m_GasType)
     {
         throw new ArgumentException("Invalid gas type");
     }
 }
Ejemplo n.º 5
0
 public void CheckGasType(eGasType i_GasType)
 {
     if (m_GasType != i_GasType)
     {
         throw new ArgumentException("Incompatible gas type");
     }
 }
Ejemplo n.º 6
0
 public void VehicleFueling(eGasType i_GasType, float i_AmountOfGasToAddInLiters)
 {
     if (i_GasType == r_GasTypeOfVehicle)
     {
         if (RemainingEnergy == MaxEnergy)
         {
             throw new Exception("Tank is already full.");
         }
         else
         {
             try
             {
                 RemainingEnergy += i_AmountOfGasToAddInLiters;
             }
             catch (ValueOutOfRangeException)
             {
                 throw new ValueOutOfRangeException("Valid liters amount", 1.0f, r_MaxEnergy - m_RemainingEnergy);
             }
         }
     }
     else
     {
         throw new ArgumentException();
     }
 }
Ejemplo n.º 7
0
        public void ValidateRefuel(eGasType i_GasType, string i_FuelAmount, string i_LicenseNumber, Garage i_Garage)
        {
            float amountToAdd;
            bool  valid = false;

            while (!valid)
            {
                valid = true;
                while (!float.TryParse(i_FuelAmount, out amountToAdd) || amountToAdd < 0)
                {
                    Console.WriteLine("Please enter a valid numerical value for the amount ");
                    i_FuelAmount = Console.ReadLine();
                }

                try
                {
                    i_Garage.Refuel(i_LicenseNumber, i_GasType, amountToAdd);
                }
                catch (ArgumentException)
                {
                    valid = false;
                    Console.WriteLine("You entered wrong fuel type, please enter correct type");
                    i_GasType = ValidateEnumType <eGasType>(Console.ReadLine());
                }
                catch (ValueOutOfRangeException outOfRange)
                {
                    valid = false;
                    Console.WriteLine("Couldn't refuel, please enter value between {0} and {1}", outOfRange.MinValueGet, outOfRange.MaxValueGet);
                    i_FuelAmount = Console.ReadLine();
                }
            }
        }
Ejemplo n.º 8
0
            public bool ChargeOrFuelVehicle(float i_AmountToAdd, string i_LicenseID, int i_GasType)
            {
                bool isCarCharged = false;
                VehicleInTheGarage vehicleToFill = null;

                isCarCharged = IsTheVehiclesExsitsInTheGarage(i_LicenseID, ref vehicleToFill);
                if (isCarCharged)
                {
                    if ((!(vehicleToFill.Vehicle.EngineType is ElectricEngine) && i_GasType == 0) || (!(vehicleToFill.Vehicle.EngineType is GasEngine) && i_GasType != 0))
                    {
                        throw new ArgumentException();
                    }
                    else if (vehicleToFill.Vehicle.EngineType is ElectricEngine)
                    {
                        vehicleToFill.Vehicle.EngineType.ChargeOrFuelEngine(i_AmountToAdd);
                    }
                    else
                    {
                        eGasType gasTypeToFill = (eGasType)i_GasType;
                        if (!(gasTypeToFill == ((GasEngine)vehicleToFill.Vehicle.EngineType).GasType))
                        {
                            throw new ArgumentException();
                        }

                        vehicleToFill.Vehicle.EngineType.ChargeOrFuelEngine(i_AmountToAdd);
                    }
                }

                return(isCarCharged);
            }
Ejemplo n.º 9
0
        public void FillGas(eGasType i_GasType, float i_AmountOfGas)
        {
            if (i_GasType != m_GasType)
            {
                throw new ArgumentException(string.Format("The gas type dose not match the car vehicle gas type. chosen vehicle gas type is: {0}", m_GasType));
            }

            FillEnergy(i_AmountOfGas);
        }
Ejemplo n.º 10
0
        public void AddPower(eGasType i_GasType, float i_AmountOfPowerToAdd)
        {
            CheckGasType(i_GasType);
            if (i_AmountOfPowerToAdd + CurrentAmountOfPower > m_MaxAmountOfPower || i_AmountOfPowerToAdd < 0)
            {
                throw new ValueOutOfRangeException(0, m_MaxAmountOfPower);
            }

            CurrentAmountOfPower += i_AmountOfPowerToAdd;
        }
Ejemplo n.º 11
0
 public void LoadGasTank(float i_AmountToLoad, eGasType i_GasType)
 {
     if (i_GasType == m_GasType)
     {
         LoadTank(i_AmountToLoad);
     }
     else
     {
         throw new ArgumentException(string.Format("Wrong gas type. The right one is {0}", m_GasType.ToString()));
     }
 }
Ejemplo n.º 12
0
        public bool fuel(float i_NumOfLitersToAdd, eGasType i_Gastype)
        {
            bool  isAdded        = false;
            float newEnergyLevel = i_NumOfLitersToAdd + m_EnergyLevel;

            if (i_Gastype != m_GasType && newEnergyLevel <= m_MaxEnergy)
            {
                m_EnergyLevel = newEnergyLevel;
                isAdded       = true;
            }
            return(isAdded);
        }
Ejemplo n.º 13
0
        public bool Refuel(int i_AmountOfGasToAddToAdd, eGasType i_FuelType)
        {
            bool fuelOverflow        = m_CurrentAmountOfEnergy + i_AmountOfGasToAddToAdd > m_MaxAmountOfEnergy;
            bool appropriateFuelType = i_FuelType == m_GasType;
            bool isRefuelSucceeded   = !fuelOverflow && appropriateFuelType;

            if (isRefuelSucceeded)
            {
                m_CurrentAmountOfEnergy += i_AmountOfGasToAddToAdd;
            }

            return(isRefuelSucceeded);
        }
Ejemplo n.º 14
0
        public void FillUpGas(float i_GasLiters, eGasType i_GasType)
        {
            if (m_GasType != i_GasType)
            {
                throw new ArgumentException("Wrong Gas Type");
            }

            if (m_GasGauge + i_GasLiters > m_GasCapacity)
            {
                throw new ValueOutOfRangeException("Too much gas, can't fuel so much!");
            }

            m_GasGauge += i_GasLiters;
        }
Ejemplo n.º 15
0
        private void fillFuelVehicle()
        {
            string   clientlicenseNumber = string.Empty;
            eGasType gsTypeUserInput     = eGasType.Octan95;

            if (findVehicleByLicenseNumber(ref clientlicenseNumber))
            {
                Console.WriteLine("Please enter the Gas Type to fill:");
                printEnumList(gsTypeUserInput);

                if (Enum.TryParse(Console.ReadLine(), out gsTypeUserInput) && Enum.IsDefined(typeof(eGasType), gsTypeUserInput))
                {
                    Console.WriteLine("Please enter the Amount of gas you want to fill:");
                    float amountTofil;
                    if (float.TryParse(Console.ReadLine(), out amountTofil))
                    {
                        try
                        {
                            m_GarageManager.FillGasVeicle(ref clientlicenseNumber, gsTypeUserInput, amountTofil);
                            Console.WriteLine("Gas filled successfully");
                        }
                        catch (FormatException fe)
                        {
                            Console.WriteLine(fe.Message);
                            return;
                        }
                        catch (ValueOutOfRangeException ex)
                        {
                            Console.WriteLine(ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Not a valid Number to fill");
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("Incorrect gas type");
                    return;
                }
            }
            else
            {
                Console.WriteLine("License number is incorrect, going back to main menu");
                return;
            }
        }
Ejemplo n.º 16
0
 public void AddFuel(float i_AmontOfFuelToAdd, eGasType i_GasType)
 {
     if (i_GasType != m_GasType)
     {
         throw new ArgumentException("{0} fuel dose no match this vihecel engine", i_GasType.ToString());
     }
     else if (i_AmontOfFuelToAdd + m_CurrentEnergyCapacity > m_MaxEnergyCapacity || i_AmontOfFuelToAdd < 0)
     {
         throw new ValueOutOfRangeException("Fuel", k_MinEnergyCapacity, m_MaxEnergyCapacity);
     }
     else
     {
         m_CurrentEnergyCapacity += i_AmontOfFuelToAdd;
         m_EnergyLeftPercentage   = (m_CurrentEnergyCapacity / m_MaxEnergyCapacity) * 100;
     }
 }
 // Add fuel method, throws exception if the amount to add is larger then the max capacity, or the gas type is not valid
 public void AddFuel(float i_FuelToAdd, eGasType i_GasType)
 {
     if (i_GasType != m_GasType)
     {
         throw new ArgumentException("{0} type do not match to this vehicle", i_GasType.ToString());
     }
     else if (i_FuelToAdd + m_CurrentCapacity > m_MaxCapacity)
     {
         throw new ValueOutOfRangeException("Fuel", k_MinAmountToAdd, m_MaxCapacity);
     }
     else
     {
         m_CurrentCapacity     += i_FuelToAdd;
         m_CapacityInPrecentege = (m_CurrentCapacity / m_MaxCapacity) * 100;
     }
 }
Ejemplo n.º 18
0
 //-------------------------------------------------------------------------//
 //                             Pubilc Methods                              //
 //-------------------------------------------------------------------------//
 public void Refuel(eGasType i_GasType, float i_AmountOfGasToAdd)
 {
     if (i_GasType != m_GasType)
     {
         throw new ArgumentException("Incorrect fuel type");
     }
     else if (i_AmountOfGasToAdd > 0 && (i_AmountOfGasToAdd + m_CurrentGasCapasity) <= r_MaxGasCapasity)
     {
         m_CurrentGasCapasity += i_AmountOfGasToAdd;
         EnergyLeftPercent     = (m_CurrentGasCapasity * 100) / r_MaxGasCapasity;
     }
     else
     {
         throw new ValueOutOfRangeException(r_MaxGasCapasity - m_CurrentGasCapasity, 0, i_AmountOfGasToAdd);
     }
 }
Ejemplo n.º 19
0
        public static void InitEngine(eVehicleType i_Type, float i_CurrentEnergy, out Engine o_Engine, Vehicle i_Vehicle)
        {
            float    maxEnergy;
            eGasType gasType = k_EnumDefault;

            switch (i_Type)
            {
            case eVehicleType.ElectricCar:
                maxEnergy = k_MaxTimeElectricCar;
                break;

            case eVehicleType.ElectricMotorcycle:
                maxEnergy = k_MaxTimeElectricMotorcycle;
                break;

            case eVehicleType.FuelCar:
                maxEnergy = k_MaxFuelCar;
                gasType   = k_CarGas;
                break;

            case eVehicleType.FuelMotorcycle:
                maxEnergy = k_MaxFuelMotorcycle;
                gasType   = k_MotorcycleGas;
                break;

            case eVehicleType.Truck:
                maxEnergy = k_MaxFuelTruck;
                gasType   = k_TruckGas;
                break;

            default:
                throw new FormatException("Invalid Vehicle Type");
            }

            if (i_Type == eVehicleType.ElectricCar || i_Type == eVehicleType.ElectricMotorcycle)
            {
                o_Engine = new ElectricEngine(i_CurrentEnergy, maxEnergy);
            }
            else
            {
                o_Engine = new FuelEngine(gasType, i_CurrentEnergy, maxEnergy);
            }

            i_Vehicle.Engine = o_Engine;
        }
Ejemplo n.º 20
0
        public void RefuleVehicle(string i_LicenseNumber, eGasType i_GasType, float i_GasAmmount)
        {
            Vehicle relevantVehicle = getVehicle(i_LicenseNumber);

            if (relevantVehicle != null)
            {
                GasVehicle relevantgasVehicle = relevantVehicle as GasVehicle;

                if (relevantgasVehicle != null)
                {
                    relevantgasVehicle.Refuel(i_GasType, i_GasAmmount);
                }
                else
                {
                    throw new ArgumentException("You can not refule this vehicle type.");
                }
            }
        }
Ejemplo n.º 21
0
        private string getStringForGasType(eGasType i_GasType)
        {
            string gasType = string.Empty;

            if (i_GasType == eGasType.Octan95)
            {
                gasType = "octan95";
            }
            else if (i_GasType == eGasType.Octan96)
            {
                gasType = "octan96";
            }
            else if (i_GasType == eGasType.Octan98)
            {
                gasType = "octan98";
            }
            else if (i_GasType == eGasType.Soler)
            {
                gasType = "soler";
            }

            return(gasType);
        }
Ejemplo n.º 22
0
 public FuelEngine(float i_MaxEnergyCapacity, eGasType i_GasType) : base(i_MaxEnergyCapacity)
 {
     m_GasType = i_GasType;
 }
Ejemplo n.º 23
0
 //-------------------------------------------------------------------------//
 //                                Constructor                              //
 //-------------------------------------------------------------------------//
 public GasVehicle(string i_ModelName, string i_LicenceNumber, eGasType i_GasType, float i_MaxGasCapasity, float i_EnergyLeftPercent) : base(i_ModelName, i_LicenceNumber, i_EnergyLeftPercent)
 {
     r_MaxGasCapasity     = i_MaxGasCapasity;
     m_GasType            = i_GasType;
     m_CurrentGasCapasity = (r_MaxGasCapasity * i_EnergyLeftPercent) / 100; // Conversion from percent to number that represent the liters.
 }
Ejemplo n.º 24
0
 public Gas(eGasType i_GasType, float i_CurrentPower, float i_MaxPower)
     : base(i_MaxPower, i_CurrentPower)
 {
     m_GasType = i_GasType;
 }
Ejemplo n.º 25
0
 public Fuel(float i_MaxCapacity, eGasType i_GasType)
 {
     this.MaxAmount = i_MaxCapacity;
     this.m_GasType = i_GasType;
 }
Ejemplo n.º 26
0
 public GasTank(float i_CurrentAmount, float i_MaximalAmount, eGasType i_GasType) : base(i_CurrentAmount, i_MaximalAmount)
 {
     m_GasType = i_GasType;
 }
Ejemplo n.º 27
0
 // Methods:
 public bool ContainSameGasType(eGasType i_GasType)
 {
     return(r_GasType == i_GasType);
 }
Ejemplo n.º 28
0
 // Constructors:
 public GasEngine(float i_MaxCapacity, eGasType i_GasType) : base(i_MaxCapacity)
 {
     r_GasType = i_GasType;
 }
Ejemplo n.º 29
0
 public GasEngine(float i_MaxEnergy, float i_EnergyLevel, eGasType i_GasType) : base(i_MaxEnergy, i_EnergyLevel)
 {
     m_GasType = i_GasType;
 }
Ejemplo n.º 30
0
 public Gasoline(eGasType i_GasType, float i_MaxGasAmount)
 {
     r_GasType      = i_GasType;
     r_MaxGasAmount = i_MaxGasAmount;
 }