public GasEngine(eGasType i_GasType, float i_MaximumAmoutOfEnergyToCharge, float i_AmountOfEnergyLeft) { m_GasType = i_GasType; m_MaximumAmountOfEnergy = i_MaximumAmoutOfEnergyToCharge; ValidateEnergyValues(i_AmountOfEnergyLeft); AmountOfEnergyLeft = i_AmountOfEnergyLeft; }
// 5 Method- The method refuel vehicle on gas public void Refuel(string i_LicenseNumber, eGasType i_FuelType, float i_FuelToAdd) { GarageCustomer customer = FindVehicleInGarage(i_LicenseNumber); GasTank gasTank = customer.Vehicle.GasTank; if (gasTank != null) { if (!gasTank.GasType.ToString().Equals(i_FuelType.ToString())) { throw new ArgumentException("Wrong fuel type"); // throw wrong gas exception. } else { if (i_FuelToAdd < 0 || i_FuelToAdd > gasTank.MaxCapacity - gasTank.CurrentAmount) { throw new ValueOutOfRangeException(gasTank.MaxCapacity - gasTank.CurrentAmount, 0); } else { gasTank.CurrentAmount += i_FuelToAdd; customer.Vehicle.EnergyLeft = gasTank.CurrentAmount / gasTank.MaxCapacity; } } } else { throw new ArgumentException("Cannot refuel with gas an electric vehicle"); } }
private static void fillGasInVehicle() { string licenseNumber = ConsoleUI.GetField("License Number: ", !v_LettersNumbersOnly, v_NumbersOnly); ConsoleUI.CreateEnumArray <eGasType>(); string gasType = ConsoleUI.GetField("Gas Type: ", !v_LettersNumbersOnly, v_NumbersOnly); eGasType gasTypeEnum = ConsoleUI.ParseEnum <eGasType>(gasType); float gasAmount = ConsoleUI.ConvertToFloat(ConsoleUI.GetUserInput("Amount: ")); try { Garage.FuelVehicle(licenseNumber, gasTypeEnum, gasAmount); ConsoleUI.PrintToScreen("SUCCESS: Gas was filled successfully"); } catch (ArgumentException ex) { ConsoleUI.PrintToScreen(string.Format("ERROR: {0}{1}Try again or press {2} to go back to the menu", ex.Message, Environment.NewLine, ConsoleUI.Quit)); fillGasInVehicle(); } catch (ValueOutOfRangeException ex) { ConsoleUI.PrintToScreen(string.Format("{0}{1}Try again or press {2} to go back to the menu", ex.Message, Environment.NewLine, ConsoleUI.Quit)); fillGasInVehicle(); } catch { ConsoleUI.PrintToScreen(string.Format("ERROR: An error occured...{0}Try again or press {1} to go back to the menu", Environment.NewLine, ConsoleUI.Quit)); fillGasInVehicle(); } }
public void CheckGasType(eGasType i_GasType) { if (i_GasType != m_GasType) { throw new ArgumentException("Invalid gas type"); } }
public void CheckGasType(eGasType i_GasType) { if (m_GasType != i_GasType) { throw new ArgumentException("Incompatible gas type"); } }
public void VehicleFueling(eGasType i_GasType, float i_AmountOfGasToAddInLiters) { if (i_GasType == r_GasTypeOfVehicle) { if (RemainingEnergy == MaxEnergy) { throw new Exception("Tank is already full."); } else { try { RemainingEnergy += i_AmountOfGasToAddInLiters; } catch (ValueOutOfRangeException) { throw new ValueOutOfRangeException("Valid liters amount", 1.0f, r_MaxEnergy - m_RemainingEnergy); } } } else { throw new ArgumentException(); } }
public void ValidateRefuel(eGasType i_GasType, string i_FuelAmount, string i_LicenseNumber, Garage i_Garage) { float amountToAdd; bool valid = false; while (!valid) { valid = true; while (!float.TryParse(i_FuelAmount, out amountToAdd) || amountToAdd < 0) { Console.WriteLine("Please enter a valid numerical value for the amount "); i_FuelAmount = Console.ReadLine(); } try { i_Garage.Refuel(i_LicenseNumber, i_GasType, amountToAdd); } catch (ArgumentException) { valid = false; Console.WriteLine("You entered wrong fuel type, please enter correct type"); i_GasType = ValidateEnumType <eGasType>(Console.ReadLine()); } catch (ValueOutOfRangeException outOfRange) { valid = false; Console.WriteLine("Couldn't refuel, please enter value between {0} and {1}", outOfRange.MinValueGet, outOfRange.MaxValueGet); i_FuelAmount = Console.ReadLine(); } } }
public bool ChargeOrFuelVehicle(float i_AmountToAdd, string i_LicenseID, int i_GasType) { bool isCarCharged = false; VehicleInTheGarage vehicleToFill = null; isCarCharged = IsTheVehiclesExsitsInTheGarage(i_LicenseID, ref vehicleToFill); if (isCarCharged) { if ((!(vehicleToFill.Vehicle.EngineType is ElectricEngine) && i_GasType == 0) || (!(vehicleToFill.Vehicle.EngineType is GasEngine) && i_GasType != 0)) { throw new ArgumentException(); } else if (vehicleToFill.Vehicle.EngineType is ElectricEngine) { vehicleToFill.Vehicle.EngineType.ChargeOrFuelEngine(i_AmountToAdd); } else { eGasType gasTypeToFill = (eGasType)i_GasType; if (!(gasTypeToFill == ((GasEngine)vehicleToFill.Vehicle.EngineType).GasType)) { throw new ArgumentException(); } vehicleToFill.Vehicle.EngineType.ChargeOrFuelEngine(i_AmountToAdd); } } return(isCarCharged); }
public void FillGas(eGasType i_GasType, float i_AmountOfGas) { if (i_GasType != m_GasType) { throw new ArgumentException(string.Format("The gas type dose not match the car vehicle gas type. chosen vehicle gas type is: {0}", m_GasType)); } FillEnergy(i_AmountOfGas); }
public void AddPower(eGasType i_GasType, float i_AmountOfPowerToAdd) { CheckGasType(i_GasType); if (i_AmountOfPowerToAdd + CurrentAmountOfPower > m_MaxAmountOfPower || i_AmountOfPowerToAdd < 0) { throw new ValueOutOfRangeException(0, m_MaxAmountOfPower); } CurrentAmountOfPower += i_AmountOfPowerToAdd; }
public void LoadGasTank(float i_AmountToLoad, eGasType i_GasType) { if (i_GasType == m_GasType) { LoadTank(i_AmountToLoad); } else { throw new ArgumentException(string.Format("Wrong gas type. The right one is {0}", m_GasType.ToString())); } }
public bool fuel(float i_NumOfLitersToAdd, eGasType i_Gastype) { bool isAdded = false; float newEnergyLevel = i_NumOfLitersToAdd + m_EnergyLevel; if (i_Gastype != m_GasType && newEnergyLevel <= m_MaxEnergy) { m_EnergyLevel = newEnergyLevel; isAdded = true; } return(isAdded); }
public bool Refuel(int i_AmountOfGasToAddToAdd, eGasType i_FuelType) { bool fuelOverflow = m_CurrentAmountOfEnergy + i_AmountOfGasToAddToAdd > m_MaxAmountOfEnergy; bool appropriateFuelType = i_FuelType == m_GasType; bool isRefuelSucceeded = !fuelOverflow && appropriateFuelType; if (isRefuelSucceeded) { m_CurrentAmountOfEnergy += i_AmountOfGasToAddToAdd; } return(isRefuelSucceeded); }
public void FillUpGas(float i_GasLiters, eGasType i_GasType) { if (m_GasType != i_GasType) { throw new ArgumentException("Wrong Gas Type"); } if (m_GasGauge + i_GasLiters > m_GasCapacity) { throw new ValueOutOfRangeException("Too much gas, can't fuel so much!"); } m_GasGauge += i_GasLiters; }
private void fillFuelVehicle() { string clientlicenseNumber = string.Empty; eGasType gsTypeUserInput = eGasType.Octan95; if (findVehicleByLicenseNumber(ref clientlicenseNumber)) { Console.WriteLine("Please enter the Gas Type to fill:"); printEnumList(gsTypeUserInput); if (Enum.TryParse(Console.ReadLine(), out gsTypeUserInput) && Enum.IsDefined(typeof(eGasType), gsTypeUserInput)) { Console.WriteLine("Please enter the Amount of gas you want to fill:"); float amountTofil; if (float.TryParse(Console.ReadLine(), out amountTofil)) { try { m_GarageManager.FillGasVeicle(ref clientlicenseNumber, gsTypeUserInput, amountTofil); Console.WriteLine("Gas filled successfully"); } catch (FormatException fe) { Console.WriteLine(fe.Message); return; } catch (ValueOutOfRangeException ex) { Console.WriteLine(ex.Message); return; } } else { Console.WriteLine("Not a valid Number to fill"); return; } } else { Console.WriteLine("Incorrect gas type"); return; } } else { Console.WriteLine("License number is incorrect, going back to main menu"); return; } }
public void AddFuel(float i_AmontOfFuelToAdd, eGasType i_GasType) { if (i_GasType != m_GasType) { throw new ArgumentException("{0} fuel dose no match this vihecel engine", i_GasType.ToString()); } else if (i_AmontOfFuelToAdd + m_CurrentEnergyCapacity > m_MaxEnergyCapacity || i_AmontOfFuelToAdd < 0) { throw new ValueOutOfRangeException("Fuel", k_MinEnergyCapacity, m_MaxEnergyCapacity); } else { m_CurrentEnergyCapacity += i_AmontOfFuelToAdd; m_EnergyLeftPercentage = (m_CurrentEnergyCapacity / m_MaxEnergyCapacity) * 100; } }
// Add fuel method, throws exception if the amount to add is larger then the max capacity, or the gas type is not valid public void AddFuel(float i_FuelToAdd, eGasType i_GasType) { if (i_GasType != m_GasType) { throw new ArgumentException("{0} type do not match to this vehicle", i_GasType.ToString()); } else if (i_FuelToAdd + m_CurrentCapacity > m_MaxCapacity) { throw new ValueOutOfRangeException("Fuel", k_MinAmountToAdd, m_MaxCapacity); } else { m_CurrentCapacity += i_FuelToAdd; m_CapacityInPrecentege = (m_CurrentCapacity / m_MaxCapacity) * 100; } }
//-------------------------------------------------------------------------// // Pubilc Methods // //-------------------------------------------------------------------------// public void Refuel(eGasType i_GasType, float i_AmountOfGasToAdd) { if (i_GasType != m_GasType) { throw new ArgumentException("Incorrect fuel type"); } else if (i_AmountOfGasToAdd > 0 && (i_AmountOfGasToAdd + m_CurrentGasCapasity) <= r_MaxGasCapasity) { m_CurrentGasCapasity += i_AmountOfGasToAdd; EnergyLeftPercent = (m_CurrentGasCapasity * 100) / r_MaxGasCapasity; } else { throw new ValueOutOfRangeException(r_MaxGasCapasity - m_CurrentGasCapasity, 0, i_AmountOfGasToAdd); } }
public static void InitEngine(eVehicleType i_Type, float i_CurrentEnergy, out Engine o_Engine, Vehicle i_Vehicle) { float maxEnergy; eGasType gasType = k_EnumDefault; switch (i_Type) { case eVehicleType.ElectricCar: maxEnergy = k_MaxTimeElectricCar; break; case eVehicleType.ElectricMotorcycle: maxEnergy = k_MaxTimeElectricMotorcycle; break; case eVehicleType.FuelCar: maxEnergy = k_MaxFuelCar; gasType = k_CarGas; break; case eVehicleType.FuelMotorcycle: maxEnergy = k_MaxFuelMotorcycle; gasType = k_MotorcycleGas; break; case eVehicleType.Truck: maxEnergy = k_MaxFuelTruck; gasType = k_TruckGas; break; default: throw new FormatException("Invalid Vehicle Type"); } if (i_Type == eVehicleType.ElectricCar || i_Type == eVehicleType.ElectricMotorcycle) { o_Engine = new ElectricEngine(i_CurrentEnergy, maxEnergy); } else { o_Engine = new FuelEngine(gasType, i_CurrentEnergy, maxEnergy); } i_Vehicle.Engine = o_Engine; }
public void RefuleVehicle(string i_LicenseNumber, eGasType i_GasType, float i_GasAmmount) { Vehicle relevantVehicle = getVehicle(i_LicenseNumber); if (relevantVehicle != null) { GasVehicle relevantgasVehicle = relevantVehicle as GasVehicle; if (relevantgasVehicle != null) { relevantgasVehicle.Refuel(i_GasType, i_GasAmmount); } else { throw new ArgumentException("You can not refule this vehicle type."); } } }
private string getStringForGasType(eGasType i_GasType) { string gasType = string.Empty; if (i_GasType == eGasType.Octan95) { gasType = "octan95"; } else if (i_GasType == eGasType.Octan96) { gasType = "octan96"; } else if (i_GasType == eGasType.Octan98) { gasType = "octan98"; } else if (i_GasType == eGasType.Soler) { gasType = "soler"; } return(gasType); }
public FuelEngine(float i_MaxEnergyCapacity, eGasType i_GasType) : base(i_MaxEnergyCapacity) { m_GasType = i_GasType; }
//-------------------------------------------------------------------------// // Constructor // //-------------------------------------------------------------------------// public GasVehicle(string i_ModelName, string i_LicenceNumber, eGasType i_GasType, float i_MaxGasCapasity, float i_EnergyLeftPercent) : base(i_ModelName, i_LicenceNumber, i_EnergyLeftPercent) { r_MaxGasCapasity = i_MaxGasCapasity; m_GasType = i_GasType; m_CurrentGasCapasity = (r_MaxGasCapasity * i_EnergyLeftPercent) / 100; // Conversion from percent to number that represent the liters. }
public Gas(eGasType i_GasType, float i_CurrentPower, float i_MaxPower) : base(i_MaxPower, i_CurrentPower) { m_GasType = i_GasType; }
public Fuel(float i_MaxCapacity, eGasType i_GasType) { this.MaxAmount = i_MaxCapacity; this.m_GasType = i_GasType; }
public GasTank(float i_CurrentAmount, float i_MaximalAmount, eGasType i_GasType) : base(i_CurrentAmount, i_MaximalAmount) { m_GasType = i_GasType; }
// Methods: public bool ContainSameGasType(eGasType i_GasType) { return(r_GasType == i_GasType); }
// Constructors: public GasEngine(float i_MaxCapacity, eGasType i_GasType) : base(i_MaxCapacity) { r_GasType = i_GasType; }
public GasEngine(float i_MaxEnergy, float i_EnergyLevel, eGasType i_GasType) : base(i_MaxEnergy, i_EnergyLevel) { m_GasType = i_GasType; }
public Gasoline(eGasType i_GasType, float i_MaxGasAmount) { r_GasType = i_GasType; r_MaxGasAmount = i_MaxGasAmount; }