示例#1
0
        // $G$ DSN-003 (-10) You should not make UI calls from logic classes.

        // check valid electronic vehicles types
        private bool checkElectronicVehicleValid(
            ElectricVehicle i_ElectricVehicle, float[] i_MaxBatteriesTime, byte[] i_NumOfWheels, float[] i_MaxAirPressures)
        {
            string message = "Error - vehicle could not enter the garage - ";
            bool   numOfWheels = false, maxAirPressure = true, maxBatteryTime = false;

            numOfWheels = checkVehicleValidNumOfWheels(i_ElectricVehicle.Wheels, i_NumOfWheels);

            if (!numOfWheels)
            {
                message += "number of wheels is not valid";
                throw new Exception(message);
            }

            maxAirPressure = checkVehicleValidMaxAirPressure(i_ElectricVehicle.Wheels, i_MaxAirPressures);

            if (!maxAirPressure)
            {
                message += "maximum air pressure is not valid";
                throw new Exception(message);
            }

            maxBatteryTime = checkVehicleValidMaxBatteryTime(i_ElectricVehicle.MaximalBatteryTime, i_MaxBatteriesTime);

            if (!maxBatteryTime)
            {
                message += "maximum fuel tank is not valid";
                throw new Exception(message);
            }

            return(numOfWheels && maxAirPressure && maxBatteryTime);
        }
        //6. Charge an electric-based vehicle (Prompting the user for the license number and number of minutes to charge)
        public void ChargeBattery(string i_LicenseNumber, float i_MinutesToAdd)
        {
            try
            {
                ElectricVehicle vehicleToCharge = (ElectricVehicle)GetVehicleByLicense(i_LicenseNumber);

                if (vehicleToCharge.EnergyType == eEnergyType.Electricity)
                {
                    if (vehicleToCharge.RemainingBatteryTime >= vehicleToCharge.MaximalBatteryTime)
                    {
                        throw new ValueOutOfRangeException(vehicleToCharge.MaximalBatteryTime, 0, "Battery Fully Charged");
                    }

                    float minutesToAdd = vehicleToCharge.AddEnergy(vehicleToCharge, vehicleToCharge.MaximalBatteryTime, vehicleToCharge.RemainingBatteryTime, (i_MinutesToAdd / 60));
                    vehicleToCharge.RemainingBatteryTime = minutesToAdd;
                }
                else
                {
                    throw new ArgumentException("Wrong Type of Energy");
                }
            }

            catch (InvalidCastException ice)
            {
                throw new InvalidCastException("Wrong Type of Energy");
            }
        }
示例#3
0
        public void ChargeElectricVehicle(string i_PlateNumber, float i_AdditionalTime)
        {
            ElectricVehicle electricVehicle = null;

            foreach (KeyValuePair <Vehicle, Owner> vehicle in m_VehiclesInGarage)
            {
                if (vehicle.Key.LicensePlateNumber == i_PlateNumber)
                {
                    electricVehicle = vehicle.Key as ElectricVehicle;

                    if (electricVehicle == null)
                    {
                        throw new ArgumentException(string.Format("This vehicle does not match this type of operation"));
                    }
                    else
                    {
                        electricVehicle.ChargeBattery(i_AdditionalTime);
                        break;
                    }
                }
            }

            if (electricVehicle == null)
            {
                throw new ArgumentException(string.Format("Vehicle with this license plates does not exists in the Garage"));
            }
        }
示例#4
0
        public void Recharge(string i_LicensePlateNumber, float i_HowMuchToFill)
        {
            int vehicleLocation = CheckIfVehicleInGarage(i_LicensePlateNumber);

            if (vehicleLocation == k_NotInGarage)
            {
                throw new ArgumentException("Vehicle is NOT in garage");
            }

            ElectricVehicle customerVehicle = r_AllVehiclesInGarage[vehicleLocation] as ElectricVehicle;

            if (customerVehicle == null)
            {
                throw new ArgumentException("NOT an Electric vehicle");
            }

            float newBatteryLeft = customerVehicle.BatteryLeft + i_HowMuchToFill;
            float calculatedMaximumBatteryHours = customerVehicle.BatteryHourCapacity - customerVehicle.BatteryLeft;

            if (newBatteryLeft > customerVehicle.BatteryHourCapacity)
            {
                throw new ValueOutOfRangeException(calculatedMaximumBatteryHours, k_MininumRangeValue);
            }

            customerVehicle.BatteryLeft = newBatteryLeft;
        }
示例#5
0
 /// Electring Driving
 public Car(string i_ModelName, string i_LicenseNumber, float i_PercentageOfVehicleEnergy, float i_TimeRemainingBattey, eVehicleColor i_eVehicleColor, string i_WheelsManufacturerName, float WheelsCurrentAirPressure)
     : base(i_ModelName, i_LicenseNumber, i_PercentageOfVehicleEnergy)
 {
     this.m_eColor                  = i_eVehicleColor;
     this.m_eQuantityOfDoors        = eQuantityOfDoors.Four;
     this.m_MaxFuelOrMaxTimeBattery = 1.8f;
     ElectricVehicle                = new ElectricVehicle(i_TimeRemainingBattey, m_MaxFuelOrMaxTimeBattery);
     Wheels = new Wheel(i_WheelsManufacturerName, WheelsCurrentAirPressure, 31, 4);
 }
示例#6
0
        public override List <VehicleParam> GetNewVehicleParams()
        {
            List <VehicleParam> parmatersList = new List <VehicleParam>();

            parmatersList.AddRange(Vehicle.GetParams());
            parmatersList.AddRange(ElectricVehicle.GetParams());
            parmatersList.AddRange(Car.GetParams());
            return(parmatersList);
        }
示例#7
0
 /// Electric Driving
 public Motorcycle(int i_EngineCapacityIncc, string i_ModelName, string i_LicenseNumber, float i_PercentageOfVehicleEnergy, float i_TimeRemainingBattey, eLicenseType i_eLicense, string i_WheelsManufacturerName, float i_WheelsCurrentAirPressure)
     : base(i_ModelName, i_LicenseNumber, i_PercentageOfVehicleEnergy)
 {
     this.m_eLicense         = i_eLicense;
     this.EngineCapacityIncc = i_EngineCapacityIncc;
     this.m_MaxFuelOrElectic = 1.4f;
     ElectricVehicle         = new ElectricVehicle(i_TimeRemainingBattey, m_MaxFuelOrElectic);
     Wheels = new Wheel(i_WheelsManufacturerName, i_WheelsCurrentAirPressure, 33, 2);
 }
示例#8
0
        public void ChargeBatteryEnergy(float i_MinuteToLoad)
        {
            ElectricVehicle vehicle = this as ElectricVehicle;

            if (vehicle != null)
            {
                vehicle.ChargeBattery(i_MinuteToLoad);
                updateLeftedEnergyPrecent(vehicle.Energy);
            }
        }
示例#9
0
        public static new List <string> GetQuestions()
        {
            List <string> questionsToUserElectricVehicle = ElectricVehicle.GetQuestions();
            List <string> questionsToUserCar             = Car.GetQuestions();

            foreach (string str in questionsToUserCar)
            {
                questionsToUserElectricVehicle.Add(str);
            }

            return(questionsToUserElectricVehicle);
        }
示例#10
0
        public static new List <string> GetAtributes()
        {
            List <string> getAtributesFuelVehicle = ElectricVehicle.GetAtributes();
            List <string> getAtributesUserCar     = Car.GetAtributes();

            foreach (string str in getAtributesUserCar)
            {
                getAtributesFuelVehicle.Add(str);
            }

            return(getAtributesFuelVehicle);
        }
示例#11
0
        public void ChargeVehicle(string i_LicenseNumber, float i_MinutesOfChargeToAdd)
        {
            Vehicle relevantVehicle = getVehicle(i_LicenseNumber);

            if (relevantVehicle != null)
            {
                ElectricVehicle relevanElectrictVehicle = relevantVehicle as ElectricVehicle;
                if (relevanElectrictVehicle != null)
                {
                    relevanElectrictVehicle.Charge(i_MinutesOfChargeToAdd);
                }
                else
                {
                    throw new ArgumentException("You can not charge this vehicle type...");
                }
            }
        }
示例#12
0
 public void ChargeVehicleEnergy(string i_LicenseNumber, float i_MinuteToCharge)
 {
     if (IsExistInGarage(i_LicenseNumber))
     {
         ElectricVehicle electricVehicle = m_VehiclesInGarage[i_LicenseNumber].Vehicle as ElectricVehicle;
         if (electricVehicle != null)
         {
             m_VehiclesInGarage[i_LicenseNumber].Vehicle.ChargeBatteryEnergy(i_MinuteToCharge);
         }
         else
         {
             throw new ArgumentException(string.Format("Vehicle with license number '{0}' is not an Electric Vehicle", i_LicenseNumber));
         }
     }
     else
     {
         throw new ArgumentException(string.Format("Vehicle with license number '{0}' is not exist in the garage", i_LicenseNumber));
     }
 }
 public void FillInEnergyToVehicle(
     string i_LicenseNumber,
     float i_AmountToAdd,
     out bool o_IsSucceeded,
     FuelVehicle.eFuelType?i_FuelType = null)
 {
     try
     {
         o_IsSucceeded = false;
         bool isExist = r_VehicleList.TryGetValue(i_LicenseNumber, out VehicleInShop toRefuel);
         if (isExist)
         {
             if (toRefuel.m_VehicleInShop is FuelVehicle && i_FuelType != null)
             {
                 FuelVehicle fuelVehicle = toRefuel.m_VehicleInShop as FuelVehicle;
                 if (fuelVehicle != null)
                 {
                     fuelVehicle.Refueling(i_AmountToAdd, (FuelVehicle.eFuelType)i_FuelType);
                     o_IsSucceeded = true;
                 }
             }
             else if (toRefuel.m_VehicleInShop is ElectricVehicle)
             {
                 ElectricVehicle electricVehicle = toRefuel.m_VehicleInShop as ElectricVehicle;
                 if (electricVehicle != null)
                 {
                     electricVehicle.Loading(i_AmountToAdd / 60);
                     o_IsSucceeded = true;
                 }
             }
         }
         else
         {
             o_IsSucceeded = false;
             throw new ArgumentException(k_IsNotExistError);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Fail to fill in the energy in the vehicle", ex);
     }
 }
示例#14
0
        public void Charge(string i_LicenseNumber, float i_AmountHoursToAdd)
        {
            ElectricVehicle electricVehicle = m_GarageCustomer[i_LicenseNumber].Vehicle as ElectricVehicle;

            if (checkIfVehicleAlreadyInTheGarage(i_LicenseNumber))
            {
                if (electricVehicle != null)
                {
                    electricVehicle.ChargeBattery(i_AmountHoursToAdd);      // can throw exception
                }
                else
                {
                    const string k_ErrorName = "Charge - the vehicle is not electronic";
                    throw new Exception(k_ErrorName);
                }
            }
            else
            {
                const string k_ErrorName = "Charge - the vehicle doesn't exist in the garage";
                throw new Exception(k_ErrorName);
            }
        }
 public ElectricMotorcycle(Vehicle i_Vehicle) : base(i_Vehicle)
 {
     m_ElectricData = new ElectricVehicle(r_MaxHoursOfBattery);
 }
示例#16
0
 public bool CheckValidEnergyToAdd(ElectricVehicle i_VehicleToAdd, float i_EnergyToAdd, out float o_MaxAmountToAdd)
 {
     return(i_VehicleToAdd.CheckAddEnergyIsValid(i_EnergyToAdd, out o_MaxAmountToAdd));
 }
示例#17
0
 public void ChargeEnergy(ElectricVehicle i_VehicleToAddEnregy, float i_MinutesToCharge)
 {
     i_VehicleToAddEnregy.ChargeEnergy(i_MinutesToCharge);
 }
示例#18
0
 public bool IsElectricType(Vehicle i_Vehicle, out ElectricVehicle o_ElectricVehicleToReturn)
 {
     o_ElectricVehicleToReturn = i_Vehicle as ElectricVehicle;
     return(i_Vehicle is ElectricVehicle);
 }