public override void FillEnergy(eEngineEnergyTypes i_EngineType, float i_TimeToChargeInMin) { float timeToChargeInHours = i_TimeToChargeInMin / k_MinutesToHour; if (i_EngineType == this.r_EngineType) { if (i_TimeToChargeInMin < 0) { throw new ArgumentException(k_ErrAddNegativeAmountOfFuel); } if (m_RemainingBatteryInHours + timeToChargeInHours <= r_MaxBatteryLifeInHours) { m_RemainingBatteryInHours += timeToChargeInHours; } else { throw new ValueOutOfRangeExecption(0, r_MaxBatteryLifeInHours - m_RemainingBatteryInHours); } } else { throw new ArgumentException(k_WrongEngineType); } }
public void FillEnergy(eEngineEnergyTypes i_EngineType, float i_AmountToAdd) { try { r_Engine.FillEnergy(i_EngineType, i_AmountToAdd); m_RemainingEnergyPercentage = r_Engine.GetRemainingEnergyPercentage(); } catch (Exception ex) { throw ex; } }
public void FillEnergyInGarage(string i_LisenceNumber, eEngineEnergyTypes i_EnergyType, float i_AmountToAdd) // 5-6 { VehicleInGarage vehicleInGarage; bool VehicleExist = r_VehiclesDataBase.TryGetValue(i_LisenceNumber, out vehicleInGarage); try { if (VehicleExist) { vehicleInGarage.MyVehicle.FillEnergy(i_EnergyType, i_AmountToAdd); } else { throw new ArgumentException(k_GarageEmptyMsg); } } catch (Exception ex) { throw ex; } }
private HoldEngineParams getEngine(eEngineEnergyTypes i_EngineType, float i_MaxEnergy, string i_AmountFormat) { bool tryParse = false; float amountOfEnergy = -1; HoldEngineParams engine; try { while (!tryParse || amountOfEnergy < 0 || amountOfEnergy > i_MaxEnergy) { Console.WriteLine("Enter Current Amount of {0}, should be between [0,{1}]", i_AmountFormat, i_MaxEnergy); tryParse = float.TryParse(Console.ReadLine(), out amountOfEnergy); } engine = new HoldEngineParams(i_EngineType, i_MaxEnergy, amountOfEnergy); } catch (Exception ex) { throw ex; } return(engine); }
public override void FillEnergy(eEngineEnergyTypes i_EngineType, float i_FuelToAdd) { if (i_EngineType == this.r_EngineType) { if (i_FuelToAdd < 0) { throw new ArgumentException(k_ErrAddNegativeAmountOfFuel); } if (m_RemainFuelEnergy + i_FuelToAdd <= r_MaxFuelEnergy) { m_RemainFuelEnergy += i_FuelToAdd; } else { throw new ValueOutOfRangeExecption(0, r_MaxFuelEnergy - m_RemainFuelEnergy); } } else { throw new ArgumentException(k_WrongEngineType); } }
public HoldEngineParams(eEngineEnergyTypes i_EngineType, float i_MaxEnergy, float i_RemainEnergy) { r_EngineType = i_EngineType; r_MaxEnergy = i_MaxEnergy; r_RemainEnergy = i_RemainEnergy; }
public abstract void FillEnergy(eEngineEnergyTypes i_EngineType, float i_AmountToAdd);
protected Engine(eEngineEnergyTypes i_EngineType) { r_EngineType = i_EngineType; }
private void addCar(string i_Name, string i_Phone, string i_Plate, string i_VehicleModel, eEngineEnergyTypes i_EngineType, float i_MaxEnergy, string i_EnergyFormat) { HoldWheelParams wheels = getWheelParams(SupportedParameters.k_MaxCarWheelPressure, (uint)eNumOfWheels.FourWheeledCar); HoldEngineParams engine = getEngine(i_EngineType, i_MaxEnergy, i_EnergyFormat); Car.eColors color; Car.eNumOfDoors numOfDoors; int numberOfOptions = Enum.GetNames(typeof(Car.eColors)).Length; int userInput = -1; bool tryParse = false; while ((!tryParse) || (userInput > numberOfOptions) || (userInput < 1)) { Console.WriteLine("Choose a Color:"); foreach (Car.eColors colorsType in Enum.GetValues(typeof(Car.eColors))) { Console.WriteLine("{0}. {1}", (int)colorsType, colorsType.ToString()); } tryParse = int.TryParse(Console.ReadLine(), out userInput); } color = (Car.eColors)userInput; numberOfOptions = Enum.GetNames(typeof(Car.eNumOfDoors)).Length; userInput = -1; tryParse = false; while ((!tryParse) || (userInput > numberOfOptions) || (userInput < 1)) { Console.WriteLine("Choose Number of Doors:"); foreach (Car.eNumOfDoors doorsType in Enum.GetValues(typeof(Car.eNumOfDoors))) { Console.WriteLine("{0}. {1}", (int)doorsType, doorsType.ToString()); } tryParse = int.TryParse(Console.ReadLine(), out userInput); } numOfDoors = (Car.eNumOfDoors)userInput; try { HoldAddGarageVehicleParams garageParams = new HoldAddGarageVehicleParams(i_Name, i_Phone, i_VehicleModel, i_Plate, wheels, engine, Garage.eVehicleStatus.Repairing, eVehicleTypes.Car); m_Grage.AddVehicleToGarage(garageParams, (float)color, (float)numOfDoors); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void addMotorcycle(string i_Name, string i_Phone, string i_Plate, string i_VehicleModel, eEngineEnergyTypes i_EngineType, float i_MaxEnergy, string i_EnergyFormat) { HoldWheelParams wheels = getWheelParams(SupportedParameters.k_MaxMotorcycleWheelPressure, (uint)eNumOfWheels.TwoWheeledMotorcycle); HoldEngineParams engine = getEngine(i_EngineType, i_MaxEnergy, i_EnergyFormat); Motorcycle.eMotorcycleLicenceType license; int numberOfOptions = Enum.GetNames(typeof(Motorcycle.eMotorcycleLicenceType)).Length; int userInput = -1; bool tryParse = false; float engineVolume = 0; try { while ((!tryParse) || (userInput > numberOfOptions) || (userInput < 1)) { Console.WriteLine("Choose a License Type:"); foreach (Motorcycle.eMotorcycleLicenceType licenseType in Enum.GetValues(typeof(Motorcycle.eMotorcycleLicenceType))) { Console.WriteLine("{0}. {1}", (int)licenseType, licenseType.ToString()); } tryParse = int.TryParse(Console.ReadLine(), out userInput); } license = (Motorcycle.eMotorcycleLicenceType)userInput; tryParse = false; while (!tryParse) { Console.WriteLine("Enter Engine Volume"); tryParse = float.TryParse(Console.ReadLine(), out engineVolume); } HoldAddGarageVehicleParams garageParams = new HoldAddGarageVehicleParams(i_Name, i_Phone, i_VehicleModel, i_Plate, wheels, engine, Garage.eVehicleStatus.Repairing, eVehicleTypes.Motorcycle); m_Grage.AddVehicleToGarage(garageParams, (float)engineVolume, (float)license); } catch (Exception ex) { throw ex; } }
private static bool checkIfSpescificVehicleSupported(Vehicle i_Vehicle, float i_ElectricMaxEnergy, float i_MaxFuel, float i_MaxWheelPressure, eEngineEnergyTypes i_Fuel) { bool isSupported = false; bool wheelSupported = true; if (i_Vehicle.VehicleWheels != null) { foreach (Wheel wheel in i_Vehicle.VehicleWheels) { if (wheel.MaxManufacturerPressure > i_MaxWheelPressure) { wheelSupported = false; break; } } if (wheelSupported) { if ((i_Vehicle.GetEngine.GetEngineType == eEngineEnergyTypes.Electric && i_Vehicle.GetEngine.GetMaxEnergy() <= i_ElectricMaxEnergy) || (i_Vehicle.GetEngine.GetEngineType == i_Fuel && i_Vehicle.GetEngine.GetMaxEnergy() <= i_MaxFuel)) { isSupported = true; } } } return(isSupported); }