Exemple #1
0
 public Vehicle(C19_Ex03_GarageLogic.Vehicle i_vehicle, string i_NameOfOwner, string i_PhoneOfOwner)
 {
     m_vehicle      = i_vehicle;
     m_NameOfOwner  = i_NameOfOwner;
     m_PhoneOfOwner = i_PhoneOfOwner;
     m_status       = Garage.eStatusOfVehicle.InRepair;
 }
Exemple #2
0
        public string Enter(C19_Ex03_GarageLogic.Vehicle i_Vehicle, string i_NameOfOwner, string i_PhoneOfOwner)
        {
            if (i_Vehicle == null)
            {
                throw new ArgumentNullException("i_vehicle", "i_vehicle must not be null.");
            }
            if (i_NameOfOwner == null)
            {
                throw new ArgumentNullException("i_NameOfOwner", "i_NameOfOwner must not be null.");
            }
            if (i_PhoneOfOwner == null)
            {
                throw new ArgumentNullException("i_PhoneOfOwner", "i_PhoneOfOwner must not be null.");
            }

            string message = null;

            try
            {
                m_CurrentVehicleInUse = new Garage.Vehicle(i_Vehicle, i_NameOfOwner, i_PhoneOfOwner);
                m_VehiclesInGarage.Add(i_Vehicle.NumberOfLicense, m_CurrentVehicleInUse);
            }
            catch
            {
                message = "Vehicle with license number " + i_Vehicle.NumberOfLicense + " already exists in the garage.";
                m_CurrentVehicleInUse        = m_VehiclesInGarage[i_Vehicle.NumberOfLicense];
                m_CurrentVehicleInUse.Status = Garage.eStatusOfVehicle.InRepair;
            }

            return(message);
        }
Exemple #3
0
        public float GetRemainingNumberOfHoursForLifeTimeOfBatteryOfAnElectricVehicleWhoseLicenseNumberIs(string i_NumberOfLicense)
        {
            if (i_NumberOfLicense == null)
            {
                throw new ArgumentNullException("i_NumberOfLicense", "i_NumberOfLicense must not be null.");
            }

            if (not(m_VehiclesInGarage.ContainsKey(i_NumberOfLicense)))
            {
                throw new TheGarageDoesNotOwnAVehicleWithThisLicenseNumberException(i_NumberOfLicense, "i_NumberOfLicense");
            }

            C19_Ex03_GarageLogic.Vehicle vehicle = m_VehiclesInGarage[i_NumberOfLicense].ActualVehicle;

            if (not(vehicle is ElectricVehicle))
            {
                throw new TheReferredVehicleByLicenseNumberIsNotElectricException(i_NumberOfLicense, "i_NumberOfLicense");
            }

            return((vehicle as ElectricVehicle).RemainingNumberOfHoursForLifeTimeOfBattery);
        }
Exemple #4
0
        public float GetRemainingAmountOfFuelInTheTankOfAVehicleWhoseLicenseNumberIs(string i_NumberOfLicense)
        {
            if (i_NumberOfLicense == null)
            {
                throw new ArgumentNullException("i_NumberOfLicense", "i_NumberOfLicense must not be null.");
            }

            if (not(m_VehiclesInGarage.ContainsKey(i_NumberOfLicense)))
            {
                throw new TheGarageDoesNotOwnAVehicleWithThisLicenseNumberException(i_NumberOfLicense, "i_NumberOfLicense");
            }

            C19_Ex03_GarageLogic.Vehicle vehicle = m_VehiclesInGarage[i_NumberOfLicense].ActualVehicle;

            if (not(vehicle is VehicleThatOperatesOnFuel))
            {
                throw new TheReferredVehicleByLicenseNumberDoesNotOperateOnFuelException(i_NumberOfLicense, "i_NumberOfLicense");
            }

            return((vehicle as VehicleThatOperatesOnFuel).RemainingAmountOfFuelInTheTank);
        }
Exemple #5
0
        public Garage.eChargeStatus ChargeElectricVehicleWhoseLicenseNumberIs(string i_NumberOfLicense, float i_NumberOfMinutesToAddToLifeTimeOfBattery, bool i_ThrowProperExceptionOnError = true)
        {
            Garage.eChargeStatus status = Garage.eChargeStatus.Success;
            if (i_NumberOfLicense == null)
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new ArgumentNullException("i_NumberOfLicense", "i_NumberOfLicense must not be null.");
                }
                status = Garage.eChargeStatus.NumberOfLicenseIsNull;
            }
            else if (float.IsNaN(i_NumberOfMinutesToAddToLifeTimeOfBattery))
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new ArgumentNaNException("i_NumberOfMinutesToAddToLifeTimeOfBattery");
                }
                status = Garage.eChargeStatus.NumberOfMinutesToAddToLifeTimeOfBatteryIsNaN;
            }
            else if (float.IsInfinity(i_NumberOfMinutesToAddToLifeTimeOfBattery))
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new ArgumentInfinityException("i_NumberOfMinutesToAddToLifeTimeOfBattery");
                }
                status = Garage.eChargeStatus.NumberOfMinutesToAddToLifeTimeOfBatteryIsInfinity;
            }
            else if (i_NumberOfMinutesToAddToLifeTimeOfBattery <= 0f)
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new ArgumentIsNotPositiveNumberException("i_NumberOfMinutesToAddToLifeTimeOfBattery", i_NumberOfMinutesToAddToLifeTimeOfBattery);
                }
                status = Garage.eChargeStatus.NumberOfMinutesToAddToLifeTimeOfBatteryIsNotPositive;
            }
            else if (not(m_VehiclesInGarage.ContainsKey(i_NumberOfLicense)))
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new TheGarageDoesNotOwnAVehicleWithThisLicenseNumberException(i_NumberOfLicense, "i_NumberOfLicense");
                }
                status = eChargeStatus.TheGarageDoesNotHaveAVehicleWithThisLicenseNumber;
            }
            else
            {
                C19_Ex03_GarageLogic.Vehicle vehicle = m_VehiclesInGarage[i_NumberOfLicense].ActualVehicle;
                if (not(vehicle is ElectricVehicle))
                {
                    if (i_ThrowProperExceptionOnError)
                    {
                        throw new TheReferredVehicleByLicenseNumberIsNotElectricException(i_NumberOfLicense, "i_NumberOfLicense");
                    }
                    status = eChargeStatus.TheReferredVehicleIsNotElectric;
                }
                else
                {
                    ElectricVehicle electricVehicle = vehicle as ElectricVehicle;
                    switch (electricVehicle.Charge(TimeUnitConverter.FromMinutesToHours(i_NumberOfMinutesToAddToLifeTimeOfBattery), i_ThrowProperExceptionOnError))
                    {
                    case ElectricVehicle.eChargeStatus.NumberOfHoursToAddToLifeTimeOfBatteryIsNaN:
                        status = Garage.eChargeStatus.NumberOfMinutesToAddToLifeTimeOfBatteryIsNaN;
                        break;

                    case ElectricVehicle.eChargeStatus.NumberOfHoursToAddToLifeTimeOfBatteryIsInfinity:
                        status = Garage.eChargeStatus.NumberOfMinutesToAddToLifeTimeOfBatteryIsInfinity;
                        break;

                    case ElectricVehicle.eChargeStatus.NumberOfHoursToAddToLifeTimeOfBatteryIsNotPositive:
                        status = Garage.eChargeStatus.NumberOfMinutesToAddToLifeTimeOfBatteryIsNotPositive;
                        break;

                    case ElectricVehicle.eChargeStatus.Overflow:
                        status = eChargeStatus.Overflow;
                        break;

                    case ElectricVehicle.eChargeStatus.Success:
                        status = eChargeStatus.Success;
                        break;
                    }
                }
            }

            return(status);
        }
Exemple #6
0
        public Garage.eRefuelStatus RefuelVehicleWhoseLicenseNumberIs(string i_NumberOfLicense, VehicleThatOperatesOnFuel.eTypeOfFuel i_TypeOfFuel, float i_AmountOfFuelToFillTheTankInLiters, bool i_ThrowProperExceptionOnError = true)
        {
            Garage.eRefuelStatus status;
            if (i_NumberOfLicense == null)
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new ArgumentNullException("i_NumberOfLicense", "i_NumberOfLicense must not be null.");
                }
                status = Garage.eRefuelStatus.NumberOfLicenseIsNull;
            }
            else if (float.IsNaN(i_AmountOfFuelToFillTheTankInLiters))
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new ArgumentNaNException("i_AmountOfFuelToFillTheTankInLiters");
                }
                status = Garage.eRefuelStatus.AmountOfFuelToAddIsNaN;
            }
            else if (float.IsInfinity(i_AmountOfFuelToFillTheTankInLiters))
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new ArgumentInfinityException("i_AmountOfFuelToFillTheTankInLiters");
                }
                status = Garage.eRefuelStatus.AmountOfFuelToAddIsInfinity;
            }
            else if (not(m_VehiclesInGarage.ContainsKey(i_NumberOfLicense)))
            {
                if (i_ThrowProperExceptionOnError)
                {
                    throw new TheReferredVehicleByLicenseNumberDoesNotOperateOnFuelException(i_NumberOfLicense, "i_NumberOfLicense");
                }
                status = Garage.eRefuelStatus.TheGarageDoesNotHaveAVehicleWithThisLicenseNumber;
            }
            else
            {
                C19_Ex03_GarageLogic.Vehicle vehicle = m_VehiclesInGarage[i_NumberOfLicense].ActualVehicle;
                if (not(vehicle is VehicleThatOperatesOnFuel))
                {
                    if (i_ThrowProperExceptionOnError)
                    {
                        throw new TheGarageDoesNotOwnAVehicleWithThisLicenseNumberException(i_NumberOfLicense, "i_NumberOfLicense");
                    }
                    status = Garage.eRefuelStatus.TheReferredVehicleDoesNotOperateOnFuel;
                }
                else
                {
                    VehicleThatOperatesOnFuel vehicleThatOperatesOnFuel = vehicle as VehicleThatOperatesOnFuel;
                    switch (vehicleThatOperatesOnFuel.Refuel(i_AmountOfFuelToFillTheTankInLiters, i_TypeOfFuel, i_ThrowProperExceptionOnError))
                    {
                    case VehicleThatOperatesOnFuel.eRefuelStatus.AmountOfFuelToAddIsNaN:
                        status = Garage.eRefuelStatus.AmountOfFuelToAddIsNaN;
                        break;

                    case VehicleThatOperatesOnFuel.eRefuelStatus.AmountOfFuelToAddIsInfinity:
                        status = Garage.eRefuelStatus.AmountOfFuelToAddIsInfinity;
                        break;

                    case VehicleThatOperatesOnFuel.eRefuelStatus.FuelTankOverflow:
                        status = Garage.eRefuelStatus.FuelTankOverflow;
                        break;

                    case VehicleThatOperatesOnFuel.eRefuelStatus.TypesOfFuelsAreIncompatible:
                        status = Garage.eRefuelStatus.TypesOfFuelsAreIncompatible;
                        break;

                    default:
                    case VehicleThatOperatesOnFuel.eRefuelStatus.Success:
                        status = Garage.eRefuelStatus.Success;
                        break;
                    }
                }
            }

            return(status);
        }