Esempio n. 1
0
        private static ElectricCar initNewElectricCar(string i_LicensePlateSrting, string i_VehicleModel, float i_EnergyLeft, string i_WheelManufacturer, float i_WheelCurrentAirPressure, string[] i_Parameters)
        {
            const bool  v_IgnoreCase           = true;
            const float k_MaxCarHoursInBattery = 2.2f;

            if (i_EnergyLeft > k_MaxCarHoursInBattery)
            {
                throw new ValueOutOfRangeException(k_MaxCarHoursInBattery);
            }

            ElectricEngine engine = new ElectricEngine(k_MaxCarHoursInBattery, i_EnergyLeft, null);

            if (i_WheelCurrentAirPressure > k_MaxAirPressureInCarWheels)
            {
                throw new ValueOutOfRangeException(k_MaxAirPressureInCarWheels);
            }

            List <Wheel> wheels = new List <Wheel>(k_NumberOfWheelsInCar);

            for (int i = 0; i < k_NumberOfWheelsInCar; i++)
            {
                wheels.Add(new Wheel(i_WheelManufacturer, i_WheelCurrentAirPressure, k_MaxAirPressureInCarWheels));
            }

            Car.eCarColor   color      = (Car.eCarColor)Enum.Parse(typeof(Car.eCarColor), i_Parameters[0], v_IgnoreCase);
            Car.eNumOfDoors numOfDoors = (Car.eNumOfDoors)Enum.Parse(typeof(Car.eNumOfDoors), i_Parameters[1], v_IgnoreCase);

            return(new ElectricCar(i_LicensePlateSrting, i_VehicleModel, wheels, engine, color, numOfDoors));
        }
Esempio n. 2
0
        private static ElectricMotorcycle initNewElectricMotorcycle(string i_LicensePlateSrting, string i_VehicleModel, float i_EnergyLeft, string i_WheelManufacturer, float i_WheelCurrentAirPressure, string[] i_Parameters)
        {
            const bool  v_IgnoreCase = true;
            const float k_MaxAirPressureInElectricMotorcycleWheels = 31;
            const float k_MaxMotorcycleHoursInBattery = 1.2f;

            if (i_EnergyLeft > k_MaxMotorcycleHoursInBattery)
            {
                throw new ValueOutOfRangeException(k_MaxMotorcycleHoursInBattery);
            }

            int            engineVolume = int.Parse(i_Parameters[1]);
            ElectricEngine engine       = new ElectricEngine(k_MaxMotorcycleHoursInBattery, i_EnergyLeft, engineVolume);

            if (i_WheelCurrentAirPressure > k_MaxAirPressureInElectricMotorcycleWheels)
            {
                throw new ValueOutOfRangeException(k_MaxAirPressureInElectricMotorcycleWheels);
            }

            List <Wheel> wheels = new List <Wheel>(k_NumberOfWheelsInMotorcycle);

            for (int i = 0; i < k_NumberOfWheelsInMotorcycle; i++)
            {
                wheels.Add(new Wheel(i_WheelManufacturer, i_WheelCurrentAirPressure, k_MaxAirPressureInElectricMotorcycleWheels));
            }

            Motorcycle.eLicenseType licenseType =
                (Motorcycle.eLicenseType)Enum.Parse(typeof(Motorcycle.eLicenseType), i_Parameters[0], v_IgnoreCase);

            return(new ElectricMotorcycle(i_LicensePlateSrting, i_VehicleModel, wheels, licenseType, engine));
        }
Esempio n. 3
0
        public bool ChargeVehicle(string i_PlateNumber, float i_Amount)
        {
            bool isCharged = false;

            GarageCustomer customer = FindCustomerByPlateNumber(i_PlateNumber);

            if (customer == null)
            {
                return(false);
            }
            IEngine engine = customer.Vehicle.Engine;

            if (engine.EngineType() == typeof(ElectricEngine))
            {
                ElectricEngine electricEngine = (ElectricEngine)engine;

                isCharged = electricEngine.chargeBattery(i_Amount);
            }
            else
            {
                throw new ArgumentException("Trying to put gas in an electric engine");
            }

            return(isCharged);
        }
Esempio n. 4
0
        public override void InsertAnswer(string i_UserInput, int i_Index)
        {
            switch (i_Index)
            {
            case 1:
                if (i_UserInput == eEngineTypes.Gas.ToString())
                {
                    m_EnergySource = new GasEngine(eFuelType.Octan98, k_MaxGasEngine);
                }
                else
                {
                    m_EnergySource = new ElectricEngine(k_MaxElectricalEngine);
                }

                break;

            case 2:
                m_NumberOfDoors = (eNumberOfDoors)Enum.Parse(typeof(eNumberOfDoors), i_UserInput);
                break;

            case 3:
                m_CarColor = (eCarColor)Enum.Parse(typeof(eCarColor), i_UserInput);
                break;

            case 4:
                m_EnergySource.CurrentEnergy = float.Parse(i_UserInput);
                break;

            default:
                break;
            }
        }
        private Engine createEngine(eVehicleType i_VehicleType)
        {
            Engine engine = null;

            switch (i_VehicleType)
            {
            case eVehicleType.ElectricCar:
                engine = new ElectricEngine(k_ElectricCarMaxHours);
                break;

            case eVehicleType.ElectricMotorcycle:
                engine = new ElectricEngine(k_ElectricMotorcycleMaxHours);
                break;

            case eVehicleType.FuelBasedCar:
                engine = new FuelEngine(k_CarFuelType, k_CarMaxFuel);
                break;

            case eVehicleType.FuelBasedMotorcycle:
                engine = new FuelEngine(k_MotorCycleFuelType, k_MotorcycleMaxFuel);
                break;

            case eVehicleType.FuelBasedTruck:
                engine = new FuelEngine(k_TruckFuelType, k_TruckMaxFuel);
                break;
            }

            return(engine);
        }
Esempio n. 6
0
        public static Engine CreateEngine(Vehicle.eVehicleTypes i_VehicleType, float i_EnergyLevel)
        {
            Engine engine = null;

            switch (i_VehicleType)
            {
            case Vehicle.eVehicleTypes.GasMotorcycle:
                engine = new GasEngine(Vehicle.eGasTypes.Octan95, i_EnergyLevel, 5.5f);
                break;

            case Vehicle.eVehicleTypes.ElectricMotorcycle:
                engine = new ElectricEngine(i_EnergyLevel, 2.7f);
                break;

            case Vehicle.eVehicleTypes.GasCar:
                engine = new GasEngine(Vehicle.eGasTypes.Octan98, i_EnergyLevel, 42.0f);
                break;

            case Vehicle.eVehicleTypes.ElectricCar:
                engine = new ElectricEngine(i_EnergyLevel, 2.5f);
                break;

            case Vehicle.eVehicleTypes.Truck:
                engine = new GasEngine(Vehicle.eGasTypes.Octan96, i_EnergyLevel, 135.0f);
                break;
            }

            return(engine);
        }
Esempio n. 7
0
        public Car(
            eVehicle i_TypeOfVehicle,
            string i_ModelName,
            string i_LicenseNumber,
            string i_OwnerPhoneNumber,
            string i_OwnerName,
            string i_WheelManufacturer,
            float i_CurrentAirPressure,
            float i_CurrentCapacity)
            : base(
                i_TypeOfVehicle,
                i_ModelName,
                i_LicenseNumber,
                i_OwnerPhoneNumber,
                i_OwnerName,
                i_WheelManufacturer,
                i_CurrentAirPressure,
                i_CurrentCapacity)
        {
            AddWheels(i_CurrentAirPressure, 4, 32);

            if (i_TypeOfVehicle == eVehicle.ElectricCar)
            {
                CurrEngine = new ElectricEngine(2.1f);
                CurrEngine.CurrentCapacity = i_CurrentCapacity;
            }
            else
            {
                CurrEngine = new FuelEngine(60, eFuelType.Octane96);
                CurrEngine.CurrentCapacity = i_CurrentCapacity;
            }
        }
Esempio n. 8
0
        public bool FillFuelToMax(Vehicle i_VehicleToActOn, eEngineType i_EngineTypeBasedOnMethodUse, eFuelType i_TypeOfFuelToAdd, float i_AmountOfFuel)
        {
            bool resultOfFuel = false;

            switch (i_EngineTypeBasedOnMethodUse)
            {
            case eEngineType.Fuel:
                FuelEngine currentFuelEngine = m_VehicleInGarage.VehicleEngine as FuelEngine;
                resultOfFuel = currentFuelEngine.ChargeEnergyIfPossible(i_AmountOfFuel, i_TypeOfFuelToAdd);
                break;

            case eEngineType.Electric:
                ElectricEngine currentElectricEngine = m_VehicleInGarage.VehicleEngine as ElectricEngine;
                resultOfFuel = currentElectricEngine.ChargeEnergyIfPossible(i_AmountOfFuel);
                break;
            }

            if (resultOfFuel)
            {
                i_VehicleToActOn.PercentOfEnergyLeft = 100;
                i_VehicleToActOn.VehicleEngine.CurrentAmountOfEnergy = i_VehicleToActOn.VehicleEngine.MaxAmountOfEnergy;
            }

            return(resultOfFuel);
        }
Esempio n. 9
0
        protected virtual List <string> RequiredInfoForCreationOfVehicle()
        {
            List <string> engineInformation;

            if (r_Engine is ElectricEngine)
            {
                ElectricEngine electricEngine = r_Engine as ElectricEngine;
                engineInformation = electricEngine.RequiredInfoForCreation();
            }
            else
            {
                FuelEngine fuelEngine = r_Engine as FuelEngine;
                engineInformation = fuelEngine.RequiredInfoForCreation();
            }

            List <string> wheelsInformation = m_Wheels[0].RequiredInfoForCreation();
            List <string> requiredInfo      = new List <string>();

            requiredInfo.Add("Please enter vehicle MODEL NAME:");
            foreach (string info in engineInformation)
            {
                requiredInfo.Add(info);
            }

            foreach (string info in wheelsInformation)
            {
                requiredInfo.Add(info);
            }

            return(requiredInfo);
        }
Esempio n. 10
0
        public void FillElectric(string i_LicenseId, int i_amountOfMinutes)
        {
            float          toHour = (i_amountOfMinutes / 60) + (i_amountOfMinutes % 60);
            ElectricEngine eng    = m_Vehicles[i_LicenseId].Vehicle.Engine as ElectricEngine;

            eng.FillEnergy(toHour);
        }
Esempio n. 11
0
 public void ReCharge(string i_PlateNumber, float i_MinutesAmount)
 {
     if (r_VehiclesStorage.ContainsKey(i_PlateNumber) == true)
     {
         Vehicle currentVehicle = r_VehiclesStorage[i_PlateNumber].Vehicle;
         if (currentVehicle.Engine.Type == eEngineType.Electric)
         {
             ElectricEngine currentEngine = currentVehicle.Engine as ElectricEngine;
             if (currentEngine.CurrentEnergyCapacity + i_MinutesAmount <= currentEngine.MaxEnergyCapacity)
             {
                 currentEngine.ReCharge(i_MinutesAmount);
                 currentVehicle.EnergyPresentage = (currentEngine.CurrentEnergyCapacity / currentEngine.MaxEnergyCapacity) * 100;
             }
             else
             {
                 throw new ValueOutOfRangeException(0, currentEngine.MaxEnergyCapacity - currentEngine.CurrentEnergyCapacity, "Exceeding the maximum charge capacity!");
             }
         }
         else
         {
             throw new ArgumentException("Engine Type mismatch! Please Enter Electric Car Plate Number");
         }
     }
     else
     {
         throw new ArgumentException("Vehicle does not exist in the garage!");
     }
 }
Esempio n. 12
0
        public void ChargeElectricVehicle(string i_LicensePlate, float i_MinutesToCharge)
        {
            VehicleInGarage requestedVehicle = SearchForVehicleInGarage(i_LicensePlate);
            float           hoursToCharge    = i_MinutesToCharge / 60;
            bool            isElectricEngine = requestedVehicle.TheVehicle.VehicleEngine is ElectricEngine;

            if (requestedVehicle != null)
            {
                if (isElectricEngine)
                {
                    ElectricEngine vehicleEngine = requestedVehicle.TheVehicle.VehicleEngine as ElectricEngine;
                    if (requestedVehicle.TheVehicle.VehicleEngine.CurrentAmountOfEnergy + hoursToCharge <= requestedVehicle.TheVehicle.VehicleEngine.MaximumAmountOfEnergy)
                    {
                        requestedVehicle.TheVehicle.VehicleEngine.CurrentAmountOfEnergy += hoursToCharge;
                        requestedVehicle.TheVehicle.VehicleEngine.PercentOfEnergyLeft    = (requestedVehicle.TheVehicle.VehicleEngine.CurrentAmountOfEnergy / requestedVehicle.TheVehicle.VehicleEngine.MaximumAmountOfEnergy) * 100;
                    }
                    else
                    {
                        float maxValue = (requestedVehicle.TheVehicle.VehicleEngine.MaximumAmountOfEnergy - requestedVehicle.TheVehicle.VehicleEngine.CurrentAmountOfEnergy) * 60;
                        throw new ValueOutOfRangeException(0, maxValue);
                    }
                }
                else
                {
                    throw new ArgumentException("The requested vehicle is not electric!");
                }
            }
            else
            {
                throw new ArgumentException("The requested vehicle does not run on gas!");
            }
        }
Esempio n. 13
0
        public void ChargeVehicle(string i_LicenseNumber, float i_HoursToFill)
        {
            bool vehicleExists = r_AllVehicles.TryGetValue(i_LicenseNumber, out Vehicle requestedVehicle);

            if (vehicleExists)
            {
                ElectricEngine thisElectricEngine = requestedVehicle.VehicleEngine as ElectricEngine;
                if (thisElectricEngine != null)
                {
                    if (thisElectricEngine.MaxEnergyCapacity > thisElectricEngine.CurrentEnergyCapacity)
                    {
                        if (thisElectricEngine.MaxEnergyCapacity
                            < i_HoursToFill + thisElectricEngine.CurrentEnergyCapacity || i_HoursToFill <= 0)
                        {
                            float maxAmountToFill = thisElectricEngine.MaxEnergyCapacity
                                                    - thisElectricEngine.CurrentEnergyCapacity;
                            throw new ValueOutOfRangeException(@"Invalid amount to fill", 0, maxAmountToFill);
                        }

                        thisElectricEngine.ChargeBattery(i_HoursToFill);
                    }
                }
                else
                {
                    throw new KeyNotFoundException(@"This is not an electric vehicle");
                }
            }
            else
            {
                throw new KeyNotFoundException(@"This vehicle is not it the garage");
            }
        }
Esempio n. 14
0
 internal ElectricCar(string i_ModelName, string i_LicenseNumber, string i_OwnerName, string i_OwnerPhoneNumber)
     : base(i_ModelName, i_LicenseNumber, i_OwnerName, i_OwnerPhoneNumber)
 {
     ElectricMotorcycleEngine         = new ElectricEngine();
     ElectricMotorcycleEngine.MaxTime = c_MaxAmountOfElectricity;
     EnergyType  = ElectricMotorcycleEngine;
     TypeOfColor = AggregateEnumTypes.eTypeColor.Black;
     NumOfDoors  = AggregateEnumTypes.eNumOfDoors.Two;
 }
 internal ElectricMotorcycle(string i_ModelName, string i_LicenseNumber, string i_OwnerName, string i_OwnerPhoneNumber)
     : base(i_ModelName, i_LicenseNumber, i_OwnerName, i_OwnerPhoneNumber)
 {
     ElectricMotorcycleEngine         = new ElectricEngine();
     ElectricMotorcycleEngine.MaxTime = c_MaxAmountOfElectricity;
     EnergyType     = ElectricMotorcycleEngine;
     TypeOfLicenses = AggregateEnumTypes.eTypeOfLicences.A;
     EngineVolume   = 0;
 }
Esempio n. 16
0
        public void ChargeVehicle(string i_LicenseNumber, string i_AmountToCharge)
        {
            Vehicle vehicle;

            vehicle = m_VehicleDetailsList[i_LicenseNumber].Vehicle;
            checkVehicleIsElectricType(vehicle);
            ElectricEngine engine = vehicle.VehicleEngine as ElectricEngine;

            engine.ReCharge(float.Parse(i_AmountToCharge));
        }
Esempio n. 17
0
File: Car.cs Progetto: nis94/Garage
 internal Car(eVehicleType i_VehicleType, string i_plateNumber) : base(4, 32, i_VehicleType, i_plateNumber)
 {
     if (i_VehicleType.Equals(eVehicleType.ElectricCar))
     {
         m_Engine = new ElectricEngine(2.1f);
     }
     else
     {
         m_Engine = new FuelEngine(60f, eFuelType.Octan96);
     }
 }
Esempio n. 18
0
 internal Motorbike(eVehicleType i_VehicleType, string i_plateNumber) : base(2, 30, i_VehicleType, i_plateNumber)
 {
     if (i_VehicleType.Equals(eVehicleType.ElectricMotorbike))
     {
         m_Engine = new ElectricEngine(1.2f);
     }
     else
     {
         m_Engine = new FuelEngine(7f, eFuelType.Octan95);
     }
 }
Esempio n. 19
0
        public void FillElectric(string i_LicenseId, int i_AmountOfMinutes)
        {
            float          toHour = i_AmountOfMinutes / 60f;
            ElectricEngine eng    = m_Vehicles[i_LicenseId].Vehicle.Engine as ElectricEngine;

            if (eng == null)
            {
                throw new ArgumentException(string.Format(k_NotElectricVehicle, i_LicenseId, Environment.NewLine));
            }

            eng.ChargeBattery(toHour);
        }
Esempio n. 20
0
 public void ChargeVehicle(string i_LicenseNumber, float i_ChargeAmmountInMinutes)
 {
     if (m_VechicleRecords[i_LicenseNumber].Vehicle.Engine is ElectricEngine)
     {
         ElectricEngine electricEngine = m_VechicleRecords[i_LicenseNumber].Vehicle.Engine as ElectricEngine;
         electricEngine.ChargeBattery(i_ChargeAmmountInMinutes / k_ParseMinuteToHours);
     }
     else
     {
         throw new ArgumentException("Trying to charge vechicle with fuel engine");
     }
 }
Esempio n. 21
0
        public Car CreateNewElectricCar(Dictionary <string, string> i_VehicleDictionary)
        {
            i_VehicleDictionary.Add("Number of wheels:", "4");
            i_VehicleDictionary.Add("Wheel maximal air pressure:", "31");
            i_VehicleDictionary.Add("max battery time:", "1.8");
            validationOfEngine(i_VehicleDictionary["remaining battery time in hours:"], i_VehicleDictionary["max battery time:"]);
            validationOfCar(i_VehicleDictionary);
            validationOfWheels(i_VehicleDictionary);
            ElectricEngine electricEngine = new ElectricEngine(i_VehicleDictionary);
            Car            electricCar    = new Car(i_VehicleDictionary, electricEngine);

            return(electricCar);
        }
Esempio n. 22
0
 internal MotorCycle(string i_LicenseNumber, eVehicleType i_VehicleType)
     : base(i_LicenseNumber, m_MaxWheelAirPressure, m_NumOfWheels, FuelEngine.eFuelType.Octan95)
 {
     if (i_VehicleType == eVehicleType.FuelMotorCycle)
     {
         EngineSystem = new FuelEngine(k_MaxFuelAmount, FuelEngine.eFuelType.Octan95);
     }
     else
     {
         EngineSystem = new ElectricEngine(k_MaxBatteryTime);
     }
     VehicleType = eVehicleType.FuelMotorCycle;
 }
Esempio n. 23
0
        public Motorcycle CreateNewElectricMotorcycle(Dictionary <string, string> i_VehicleDictionary)
        {
            i_VehicleDictionary.Add("Number of wheels:", "2");
            i_VehicleDictionary.Add("Wheel maximal air pressure:", "33");
            i_VehicleDictionary.Add("max battery time:", "1.4");
            validationOfEngine(i_VehicleDictionary["remaining battery time in hours:"], i_VehicleDictionary["max battery time:"]);
            validationOfMotorcycle(i_VehicleDictionary);
            validationOfWheels(i_VehicleDictionary);
            ElectricEngine electricEngine     = new ElectricEngine(i_VehicleDictionary);
            Motorcycle     electricMotorcycle = new Motorcycle(i_VehicleDictionary, electricEngine);

            return(electricMotorcycle);
        }
Esempio n. 24
0
        internal Car(string i_LicenseNumber, eVehicleType i_VehicleType)
            : base(i_LicenseNumber, k_MaxWheelAirPressure, k_NumOfWheels, FuelEngine.eFuelType.Octan98)
        {
            if (i_VehicleType == eVehicleType.FuelCar)
            {
                EngineSystem = new FuelEngine(k_MaxFuelAmount, FuelEngine.eFuelType.Octan98);
            }

            else
            {
                EngineSystem = new ElectricEngine(k_MaxBatteryTime);
            }
            VehicleType = i_VehicleType;
        }
Esempio n. 25
0
        public void ChargeElectricVehicle(string i_LicensePlateNumber, float i_HoursToCharge)
        {
            ElectricEngine electricEngine = r_Vehicles[i_LicensePlateNumber].Engine as ElectricEngine;

            if (electricEngine != null)
            {
                electricEngine.ChargeBattery(i_HoursToCharge);
            }
            else
            {
                throw new ArgumentException();
            }

            r_Vehicles[i_LicensePlateNumber].UpdateVehicleEngineEnergyPrecentage();
        }
        private static IEngine InitializeEngine(DataBase i_UserInput)
        {
            IEngine engine;

            if (i_UserInput.m_IsElectric)
            {
                engine = new ElectricEngine(i_UserInput.m_BatteryTimeLeft, i_UserInput.m_MaxBatteryLife);
            }
            else
            {
                engine = new FuelEngine(i_UserInput.m_FuelType, i_UserInput.m_AmountOfFuel, i_UserInput.m_MaxFuelAmount);
            }

            return(engine);
        }
Esempio n. 27
0
        // resposible to validate data and charge engine
        public void ChargeEnergy(string i_LicenseNumber, float i_MinutesToCharge)
        {
            Customer currentCar = m_Customers[i_LicenseNumber];

            if (currentCar.CustomerVehicle.VehicleEngine.TypeOfEngine != "Electric")
            {
                throw new Exception("this Vehicle is not electric Vehicle");
            }

            ElectricEngine engineToCharge = (ElectricEngine)currentCar.CustomerVehicle.VehicleEngine;

            float HowMuchToCharge = i_MinutesToCharge / 60;

            engineToCharge.FillEnergy(HowMuchToCharge);
        }
Esempio n. 28
0
        public void RechargeElectric(string i_VehicleId, float i_AmountToRecharge)
        {
            StoredVehicle  vehicleToRecharge = null;
            ElectricEngine engineToRecharge  = null;
            bool           isEngineElectric  = false;

            vehicleToRecharge = getStoredVehicle(i_VehicleId);
            isEngineElectric  = vehicleToRecharge.Vehicle.Engine is ElectricEngine;
            if (!isEngineElectric)
            {
                throw new ArgumentException("Engine is not ElectricEngine.");
            }

            engineToRecharge = (vehicleToRecharge.Vehicle.Engine as ElectricEngine);
            engineToRecharge.Recharge(i_AmountToRecharge);
            vehicleToRecharge.Vehicle.calculateCurrentEnergyPercent();
        }
Esempio n. 29
0
        public Car(bool isElectric)
        {
            m_VehicleWheels = VehicleCreator.createWheels(k_NumberOfWheels, k_CarMaxWheelPressure);

            m_VehicleEngine = VehicleCreator.CreateEngine(isElectric);
            if (isElectric)
            {
                ElectricEngine electricEngine = m_VehicleEngine as ElectricEngine;
                electricEngine.MaximumBatteryHours = k_MaxBatteryHoursCapacity;
            }
            else
            {
                PetrolEngine petrolEngine = m_VehicleEngine as PetrolEngine;
                petrolEngine.MaximumPetrolAmount = k_MaxPetrolLiterCapacity;
                petrolEngine.PetrolType          = k_PetrolType;
            }
        }
Esempio n. 30
0
 public void Recharge(string i_LicenseNumber, float i_AmountToCharge)
 {
     if (!IsVehicleInGarage(i_LicenseNumber))
     {
         handleVehicleNotFound(i_LicenseNumber);
     }
     else if (!IsVehicleElectric(i_LicenseNumber))
     {
         string ExceptionString = string.Format("Vehicle License Num: {0} is not an electric vehicle", i_LicenseNumber);
         throw new ArgumentException(ExceptionString);
     }
     else
     {
         ElectricEngine engine = ((ElectricEngine)m_VehivleInGarageDict[i_LicenseNumber].m_Vehicle.m_Engine);
         engine.FillEnergy(i_AmountToCharge);
     }
 }