Ejemplo n.º 1
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.º 2
0
        public override string ToString()
        {
            string engineInformationOutput = string.Format(
                @"Gas Type: {0}
Current Amount of Gas: {1} liters
Max Gas Capacity: {2} liters",
                m_GasType.ToString(),
                CurrentEnergy,
                MaxEnergyCapacity);

            return(engineInformationOutput);
        }
 // 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.º 4
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;
     }
 }
Ejemplo n.º 5
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.º 6
0
        public override string ToString()
        {
            string GasVehicleInfo = string.Format("{0}Gas type: {1}\nCurrent gas amount: {2}", base.ToString(), m_GasType.ToString(), m_CurrentGasCapasity.ToString());

            return(GasVehicleInfo);
        }