Example #1
0
        private static void getElectricInformation(GarageVehicle i_VehicleInGarageToWorkOn, StringBuilder i_EnergyInformation)
        {
            Electric energyType = (Electric)i_VehicleInGarageToWorkOn.OwnerVehicle.EnergyType;
            float    amountOfEnergyLeftInBatteryInHours = energyType.CurrentAmountOfEnergy;

            i_EnergyInformation.AppendLine(string.Format("It uses an electric battery and has {0} hours left in it", amountOfEnergyLeftInBatteryInHours));
        }
Example #2
0
        public List <string> getProperties(VehiclesCreator.VehicleType vehicleType)
        {
            List <string> properties = new List <string>();

            switch (vehicleType)
            {
            case VehiclesCreator.VehicleType.ElectricCar:
                properties.AddRange(Car.GetCarProperties());
                properties.AddRange(Electric.GetElectricProperties());
                break;

            case VehiclesCreator.VehicleType.FuelCar:
                properties.AddRange(Car.GetCarProperties());
                properties.AddRange(Fuel.GetFuelProperties());
                break;

            case VehiclesCreator.VehicleType.ElectricBike:
                properties.AddRange(MotorBike.GetMotorbikeProperties());
                properties.AddRange(Electric.GetElectricProperties());
                break;

            case VehiclesCreator.VehicleType.FuelBike:
                properties.AddRange(MotorBike.GetMotorbikeProperties());
                properties.AddRange(Fuel.GetFuelProperties());
                break;

            case VehiclesCreator.VehicleType.Truck:
                properties.AddRange(Truck.GetTruckProperties());
                properties.AddRange(Fuel.GetFuelProperties());
                break;
            }

            return(properties);
        }
Example #3
0
        private static Energy createEnergyByType(float i_CurrentEnergyLevel, float i_MaxBatterySize)
        {
            Energy energyType;

            energyType = new Electric(i_CurrentEnergyLevel, i_MaxBatterySize);

            return(energyType);
        }
Example #4
0
 public void ChargeVehicle(string i_LicenseNumber, float i_AmountOfElectricity)
 {
     if (m_VehiclesDictionary[i_LicenseNumber].m_vehicle.EnergySource is Electric)
     {
         Electric ElectricitVehicle = (Electric)m_VehiclesDictionary[i_LicenseNumber].m_vehicle.EnergySource;
         ElectricitVehicle.fillEnergy(i_AmountOfElectricity / 60);
     }
     else
     {
         throw new FormatException();
     }
 }
Example #5
0
        public void ChargeBatteryByLicense(string i_LicenseNumber, float i_BatteryTimeToAdd)
        {
            Electric electricEngine = this[i_LicenseNumber].Engine as Electric;

            if (electricEngine != null)
            {
                electricEngine.ChargeBattery(i_BatteryTimeToAdd);
                this[i_LicenseNumber].UpdateEnergyPercent();
            }
            else
            {
                throw new ArgumentException("The vehicle engine is not from electric type");
            }
        }
Example #6
0
        public override void SetVehicleDetails(Dictionary <string, object> i_VehilceInfo)
        {
            base.SetVehicleDetails(i_VehilceInfo);
            m_CarColor      = (eCarColor)i_VehilceInfo["CarColor"];
            m_NumberOfDoors = (eNumberOfDoors)i_VehilceInfo["CarDoors"];

            if (EnergyType == eEnergyTypes.Electric)
            {
                m_VehicleEnergy = new Electric((float)i_VehilceInfo["RemainingEnergy"], (float)i_VehilceInfo["MaximumEnergyCapacity"]);
            }
            else
            {
                m_VehicleEnergy = new Fuel((float)i_VehilceInfo["RemainingEnergy"], (float)i_VehilceInfo["MaximumEnergyCapacity"], (eEnergyTypes)i_VehilceInfo["EnergyType"]);
            }
        }
Example #7
0
        public override void SetVehicleDetails(Dictionary <string, object> i_VehilceInfo)
        {
            base.SetVehicleDetails(i_VehilceInfo);
            m_LicenseType  = (eLicenseTypes)i_VehilceInfo["LicenseType"];
            m_EngineVolume = (int)i_VehilceInfo["EngineVolume"];

            if (EnergyType == eEnergyTypes.Electric)
            {
                m_VehicleEnergy = new Electric((float)i_VehilceInfo["RemainingEnergy"], (float)i_VehilceInfo["MaximumEnergyCapacity"]);
            }
            else
            {
                m_VehicleEnergy = new Fuel((float)i_VehilceInfo["RemainingEnergy"], (float)i_VehilceInfo["MaximumEnergyCapacity"], (eEnergyTypes)i_VehilceInfo["EnergyType"]);
            }
        }
Example #8
0
        internal static Motorcycle CreateElectricMotocycle(Dictionary <string, object> i_ListOfProprties)
        {
            List <Wheels> ListOfWheels = CreateListWheels((string)i_ListOfProprties[GarageManager.k_ManufacturerName],
                                                          k_MotorcycleMaxAirPressureRecommended,
                                                          (float)i_ListOfProprties[GarageManager.k_CurrentAirPressure],
                                                          k_MotorcycleNumberOfWheels);

            EnergyType VehicleCEnergy = new Electric((float)i_ListOfProprties[GarageManager.k_CurrentAmountOfEnergy],
                                                     k_ElectricMotorcycleMaxAmountOfEnergy);

            Motorcycle ElectricMotocycle = new Motorcycle((string)i_ListOfProprties[GarageManager.k_ModelName],
                                                          (string)i_ListOfProprties[GarageManager.k_LicenseNumber],
                                                          ListOfWheels, VehicleCEnergy,
                                                          (eLicenseType)i_ListOfProprties[GarageManager.k_MotorcycleLicensType],
                                                          (int)i_ListOfProprties[GarageManager.k_EngineVolume]);

            return(ElectricMotocycle);
        }
Example #9
0
        internal static Car CreateElectricCar(Dictionary <string, object> i_ListOfProprties)
        {
            List <Wheels> ListOfWheels = CreateListWheels((string)i_ListOfProprties[GarageManager.k_ManufacturerName],
                                                          k_CarMaxAirPressureRecommended,
                                                          (float)i_ListOfProprties[GarageManager.k_CurrentAirPressure],
                                                          k_CarNumberOfWheels);

            EnergyType VehicleCEnergy = new Electric((float)i_ListOfProprties[GarageManager.k_CurrentAmountOfEnergy],
                                                     k_ElectricCarcleMaxAmountOfEnergy);

            Car FuelCar = new Car((string)i_ListOfProprties[GarageManager.k_ModelName],
                                  (string)i_ListOfProprties[GarageManager.k_LicenseNumber],
                                  ListOfWheels, VehicleCEnergy,
                                  (eNumberOfDoors)i_ListOfProprties[GarageManager.k_NumberOfDoors],
                                  (eCarColor)i_ListOfProprties[GarageManager.k_CarColor]);

            return(FuelCar);
        }
Example #10
0
        public static Engine NewEngine(string i_typeOfEngine, float i_maxOfQuantity, string i_typeOfGasolin)   // this function create newEngine
        {
            Engine newEngine;

            if (i_typeOfEngine.CompareTo("electric") == 0)
            {
                newEngine = new Electric(i_maxOfQuantity); // create an electric engine
            }
            else if (i_typeOfEngine.CompareTo("gasolin") == 0)
            {
                newEngine = new Gasolin(i_maxOfQuantity, i_typeOfGasolin); // create gasolin engine
            }
            else // If the engine type is not specified
            {
                newEngine = null;
            }
            return(newEngine);
        }
Example #11
0
        /**
         * This method recharges an electric based vehicle
         * Throws ArgumentException if car is not in garage or car is fuel based
         */
        public void RechargeVehicle(string i_LicenseNumber, float i_AmountToFill)
        {
            if (!IsVehicleInGarage(i_LicenseNumber))
            {
                throw new ArgumentException("The vehicle is not in the garage");
            }

            Vehicle vehicle = r_VehiclesInGarage[i_LicenseNumber];

            if (!(vehicle.EnergySource is Electric))
            {
                throw new ArgumentException("The Vehicle is not a fuel based vehicle");
            }

            Electric battery = (Electric)vehicle.EnergySource;

            battery.ChargeBatery(i_AmountToFill);
            vehicle.SetEnergyPercentage();
        }
Example #12
0
        public void ChargeElectricityBasedVehicle(string i_VehicleLicenseNumber, float i_NumberOfHoursToCharge)
        {
            GarageVehicle ownerVehicle = GetGarageVehicleByLicenseNumber(i_VehicleLicenseNumber);

            Dictionary <string, object> parametersForEnergyCharging = new Dictionary <string, object>();

            parametersForEnergyCharging.Add(Energy.k_ValueType, Electric.k_EnergyType);
            parametersForEnergyCharging.Add(Energy.k_ValueToAdd, i_NumberOfHoursToCharge);
            try
            {
                Electric ownerBattery = (Electric)ownerVehicle.OwnerVehicle.EnergyType;

                ownerVehicle.OwnerVehicle.EnergyType.AddEnergy(parametersForEnergyCharging);
                ownerVehicle.OwnerVehicle.PercentOfEnergyLeft = calculateNewPrecanteOfEnergy(ownerBattery.MaxAmountOfEnergy, ownerBattery.CurrentAmountOfEnergy);
            }
            catch (InvalidCastException ex)
            {
                throw new ArgumentException("Wrong Energy Type!", ex);
            }
        }
Example #13
0
        public bool ChargeElectricBattery(string i_LicenseNumber, float io_MinutesToAdd)
        {
            //// Gets car's license number and minutes of electricity to add.
            //// Charge the car if minutes is not above max.
            //// Return T/F if charge succeeded.

            bool isFilled = false;

            if (isExist(i_LicenseNumber))
            {
                if (r_Vehicles[i_LicenseNumber].VehicleStatus.Equals(eServiceStatuses.InRepair))
                {
                    if (r_Vehicles[i_LicenseNumber].Vehicle.EnergyType is Electric)
                    {
                        Electric currEngine = r_Vehicles[i_LicenseNumber].Vehicle.EnergyType as Electric;
                        isFilled = currEngine.ChargeBattery(io_MinutesToAdd / 60f);

                        if (isFilled)
                        {
                            float percent = currEngine.HoursLeftInBattery / currEngine.MaxHoursInBattery;
                            r_Vehicles[i_LicenseNumber].Vehicle.PercentagesOfEnergyRemaining = percent * 100f;
                        }
                    }
                    else
                    {
                        throw new FormatException("The vehicle engine is not electric!");
                    }
                }
                else
                {
                    throw new ArgumentException("The vehicle is not 'In-Repair' status. You can not work on this vehicle.");
                }
            }

            return(isFilled);
        }
Example #14
0
        private static Vehicle createElectricMotorcycle(string io_LicenseNumber)
        {
            Electric engine = new Electric(1.2f);

            return(new Motorcycle(io_LicenseNumber, 2, 30, engine));
        }
Example #15
0
        internal static void FillVehicleInfo(Vehicle io_Vehicle, Dictionary <eQuestions, object> i_FilledDictionary)
        {
            //// Gets a vehicle X and a filled dictionary.
            //// Fill the blanks in Vehicle X info by the information filled in dictionary.
            //// Throw exceptions with information about each mismatch between information needed and information given.

            if (i_FilledDictionary.ContainsKey(eQuestions.ModelName))
            {
                io_Vehicle.ModelName = i_FilledDictionary[eQuestions.ModelName].ToString();
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.CurrentFuel))
            {
                if (float.TryParse(i_FilledDictionary[eQuestions.CurrentFuel].ToString(), out float currFuel))
                {
                    Fuel engine = io_Vehicle.EnergyType as Fuel;
                    engine.CurrentFuelTank = currFuel;
                    float percent = engine.CurrentFuelTank / engine.MaxTank;
                    io_Vehicle.PercentagesOfEnergyRemaining = percent * 100f;
                }
                else
                {
                    throw new FormatException("Amount of fuel is invalid input");
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.CurrentHours))
            {
                if (float.TryParse(i_FilledDictionary[eQuestions.CurrentHours].ToString(), out float currMinutes))
                {
                    Electric engine = io_Vehicle.EnergyType as Electric;
                    engine.HoursLeftInBattery = currMinutes / 60f;
                    float percent = engine.HoursLeftInBattery / engine.MaxHoursInBattery;
                    io_Vehicle.PercentagesOfEnergyRemaining = percent * 100f;
                }
                else
                {
                    throw new FormatException("Amount of hours is invalid input");
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.CurentWheelAirPressure))
            {
                if (float.TryParse(i_FilledDictionary[eQuestions.CurentWheelAirPressure].ToString(), out float curAirPressure))
                {
                    for (int i = 0; i < io_Vehicle.Wheels.Length; i++)
                    {
                        io_Vehicle.Wheels[i].CurrentAirPressure = curAirPressure;
                    }
                }
                else
                {
                    throw new FormatException("Amount of wheel's air pressure is invalid input");
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.WheelManufacturer))
            {
                for (int i = 0; i < io_Vehicle.Wheels.Length; i++)
                {
                    io_Vehicle.Wheels[i].Manufacturer = i_FilledDictionary[eQuestions.WheelManufacturer].ToString();
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.Doors))
            {
                if (int.TryParse(i_FilledDictionary[eQuestions.Doors].ToString(), out int doors))
                {
                    (io_Vehicle as Car).Doors = (eDoors)doors;
                }
                else
                {
                    throw new FormatException("Choice of doors input is invalid");
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.LicenseType))
            {
                if (int.TryParse(i_FilledDictionary[eQuestions.LicenseType].ToString(), out int licenseType))
                {
                    (io_Vehicle as Motorcycle).LicenseType = (eLicenseTypes)licenseType;
                }
                else
                {
                    throw new FormatException("Choice of license type is invalid");
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.Color))
            {
                if (int.TryParse(i_FilledDictionary[eQuestions.Color].ToString(), out int color))
                {
                    (io_Vehicle as Car).Color = (eColors)color;
                }
                else
                {
                    throw new FormatException("Choice of color is invalid");
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.HazardousMaterials))
            {
                (io_Vehicle as Truck).HazardousMaterials = (bool)i_FilledDictionary[eQuestions.HazardousMaterials];
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.CargoCpacity))
            {
                if (float.TryParse(i_FilledDictionary[eQuestions.CargoCpacity].ToString(), out float cargo))
                {
                    (io_Vehicle as Truck).CargoVolume = cargo;
                }
                else
                {
                    throw new FormatException("Cargo capacity's input is invalid");
                }
            }

            if (i_FilledDictionary.ContainsKey(eQuestions.EngineCC))
            {
                if (int.TryParse(i_FilledDictionary[eQuestions.EngineCC].ToString(), out int engineCC))
                {
                    (io_Vehicle as Motorcycle).EngineCapacityInCC = engineCC;
                }
                else
                {
                    throw new FormatException("Engine CC's input is invalid");
                }
            }
        }
Example #16
0
        private static Vehicle createElectricCar(string io_LicenseNumber)
        {
            Electric engine = new Electric(2.1f);

            return(new Car(io_LicenseNumber, 4, 32, engine));
        }