/// <summary> /// refuel gas tank. /// </summary> public static void RefuelGasTank() { Console.WriteLine("Please Provide License number to Refuel car: "); string licenseNumber = Console.ReadLine(); Console.WriteLine("Please Provide Fuel amount to refuel: "); string fuleAmount = Console.ReadLine(); Console.WriteLine(string.Format("Please provide fuel type: 1.Octan98 2.Octan96 3.Octan95 4.Soler")); string fuelType = Console.ReadLine(); Fuel.eFuelType type = (Fuel.eFuelType) int.Parse(fuelType); foreach (Vehicle vehicle in Vehicle.r_VehiclesList) { if (vehicle.PowerSource is Fuel) { if (vehicle.LicenseNumber == licenseNumber) { if ((vehicle.PowerSource as Fuel).FuelType == type) { vehicle.PowerSource.CurrentPowerSourceAmount += float.Parse(fuleAmount); } } } else { throw new ArgumentException(); } } }
public ChargingVehicleDetails FillChargingVehicleForm(GarageManagment io_Garage) { string licenseNumber; float quantityToAdd; EnergySource.eTypeOfEnergySource typeOfEnergyChoice = new EnergySource.eTypeOfEnergySource(); Fuel.eFuelType?typeOfFuelChoice = new Fuel.eFuelType(); bool v_VehicleFound; printSign("filling Charging Form"); do { v_VehicleFound = GetVehicleLicenseNumberCheckForExisiting(io_Garage, out licenseNumber); if (v_VehicleFound == false) { Console.WriteLine("Vehicle Wasn't Found Try Again"); } }while (v_VehicleFound == false); quantityToAdd = getFloatWithoutAnyCondition("Quantity To Add"); typeOfEnergyChoice = (EnergySource.eTypeOfEnergySource)PrintAllEnumValuesGetUserChoice(typeOfEnergyChoice, "Fuel Type Choosing"); if (typeOfEnergyChoice == EnergySource.eTypeOfEnergySource.Fuel) { typeOfFuelChoice = (Fuel.eFuelType)PrintAllEnumValuesGetUserChoice(typeOfFuelChoice.Value, "Fuel Type Choosing"); } else { typeOfFuelChoice = null; } return(new ChargingVehicleDetails(licenseNumber, quantityToAdd, typeOfEnergyChoice, typeOfFuelChoice)); }
public void AddFuel(string i_LicensePlateNumber, float i_AmountOfFuel, Fuel.eFuelType i_FuelType) { Vehicle vehicleToFill = GetVehicleByLicenseNumber(i_LicensePlateNumber); Fuel vehicleFuelTank; vehicleFuelTank = vehicleToFill.GetPowerSource() as Fuel; if (vehicleFuelTank == null) { throw new ArgumentException("ERROR. The vehicle is not working on fuel"); } if (!Enum.IsDefined(typeof(Fuel.eFuelType), i_FuelType)) { throw new ArgumentException("ERROR. select fuel type from the list."); } if (vehicleFuelTank.FuelType != i_FuelType) { throw new ArgumentException(i_FuelType + " is not the right fuel type for this vehicle, " + vehicleFuelTank.FuelType + " is the right fuel type"); } vehicleToFill.AddToPowerSource(i_AmountOfFuel); vehicleToFill.UpdatePercentageOfEnergy(); if (r_ConnectedToMongoDB) { UpdateDefinition <BsonDocument> update = Builders <BsonDocument> .Update.Set("PercentageOfEnergy", vehicleToFill.PercentageOfEnergy).Set("PowerSource.AmountOfEnergyLeft", vehicleToFill.GetPowerSource().AmountOfEnergyLeft); UpdateVehicleInMongoDB(i_LicensePlateNumber, update); } }
private static EnergySource createEnergySource(VehicleInputData i_VehicleData) { EnergySource o_energySource = null; Fuel.eFuelType fuelType = 0; float maxFuelCapacity = 0; float maxBatteryTime = 0; switch (i_VehicleData.m_VehicleType) { case eVehicleType.Car: fuelType = Car.sr_FuelType; maxFuelCapacity = Car.sr_MaxFuelCapacity; break; case eVehicleType.Motorcycle: fuelType = Motorcycle.sr_FuelType; maxFuelCapacity = Motorcycle.sr_MaxFuelCapacity; break; case eVehicleType.Truck: fuelType = Truck.sr_FuelType; maxFuelCapacity = Truck.sr_MaxFuelCapacity; break; case eVehicleType.ElectricCar: maxBatteryTime = Car.sr_MaxBatteryTime; break; case eVehicleType.ElectricMotorcycle: maxBatteryTime = Motorcycle.sr_MaxBatteryTime; break; default: break; } switch (i_VehicleData.m_VehicleType) { case eVehicleType.Car: case eVehicleType.Motorcycle: case eVehicleType.Truck: o_energySource = new Fuel(i_VehicleData.m_CurrentFuelCapacity, maxFuelCapacity, fuelType); break; case eVehicleType.ElectricCar: case eVehicleType.ElectricMotorcycle: o_energySource = new Battery(i_VehicleData.m_RemainingBatteryTime, maxBatteryTime); break; default: break; } return(o_energySource); }
private static void GetVehicleFuelDataFromUser(out Fuel.eFuelType o_FuelType, out float o_CurrentFuelCapacity, out float o_MaxFuelCapacity) { GetFuelTypeFromUser(out o_FuelType); GetMaxFuelCapacityFromUser(out o_MaxFuelCapacity); GetFuelCurrentCapacityFromUser(out o_CurrentFuelCapacity, o_MaxFuelCapacity); }
public bool FuelValidationType(Fuel.eFuelType i_type) { if (((Fuel)EngineType).FuelType == i_type) { return(true); } else { return(false); } }
public void IsFuelMatch(Fuel.eFuelType i_FuelType, string i_LicenseNumber) { if (r_GarageClients[i_LicenseNumber].Vehicle.EnergyType is Electric) { throw new ArgumentException("You can't add fuel to an electric car!"); } else if (i_FuelType != ((Fuel)r_GarageClients[i_LicenseNumber].Vehicle.EnergyType).FuelType) { throw new ArgumentException("The fuel type you selected doesn't match to the vehicle fuel type!"); } }
internal void AddFuel() { string licensePlate = getLicensePlate(); m_Garage.InGarage(licensePlate); Fuel.eFuelType fuelType = getFuelType(); m_Garage.IsFuelMatch(fuelType, licensePlate); Console.Write("Please enter amount of fuel to add: "); float amountOfFuel = getValidFloat(); m_Garage.AddVehicleEnergy(amountOfFuel, licensePlate); PromptConsoleMsg("Fuel successfully added!"); }
public void RefuelVehicleByLicense(string i_LicenseNumber, Fuel.eFuelType i_FuelType, float i_FuelToAdd) { Fuel fuelEngine = this[i_LicenseNumber].Engine as Fuel; if (fuelEngine != null) { fuelEngine.Refuel(i_FuelToAdd, i_FuelType); this[i_LicenseNumber].UpdateEnergyPercent(); } else { throw new ArgumentException("The vehicle engine is not from fuel type"); } }
public void RefuelVehicle(string io_LicenseNumber, Fuel.eFuelType io_TypeOfFuel, float io_AmountToAdd) { Vehicle vehicleToRefuel = m_garageDataStructure.search(io_LicenseNumber); Fuel engineType = vehicleToRefuel.GetEnergyType as Fuel; if (engineType != null) { engineType.Refuel(io_TypeOfFuel, io_AmountToAdd); } else { //exception throw new ArgumentException(string.Format("The refueld car: {0} should be only fuel (and Not Electric) ", io_LicenseNumber), io_LicenseNumber); } }
public bool FuelVehicle(string i_LicenseNumber, float i_FuelToAdd, Fuel.eFuelType i_FuelType) { Vehicle vehicleToFuel = null; Fuel engineToFuel = null; vehicleToFuel = FindVehicleByLicense(i_LicenseNumber); engineToFuel = vehicleToFuel.EnergySource as Fuel; if (engineToFuel == null) { throw new ArgumentNullException(); } engineToFuel.FuelUp(i_FuelToAdd, i_FuelType); // bad values will throw exceptions return(true); }
public void GetfuelType(out Fuel.eFuelType i_FuelType) { int userSelectedOption; const int userOptionsNumber = 4; string input; string menu = string.Format(@"Please select fuel type 1.Soler 2.Octan95 3.Octan96 4.Octan98"); System.Console.WriteLine(menu); input = System.Console.ReadLine(); checkUserSelection(input, userOptionsNumber); userSelectedOption = int.Parse(input); i_FuelType = (Fuel.eFuelType)userSelectedOption; }
/** * This method asks refueling details. */ private void getDetailsForRefuel() { ConsoleUtils.ClearConsoleAndWrite("Please enter the license number of the vehicle you would like to refuel:"); this.m_LicenseNumber = ConsoleUtils.CheckForValidLicenseNumber(Console.ReadLine()); //checks that the energy types match if (m_CheckForEnergyType = checkEnergyType(m_LicenseNumber)) { ConsoleUtils.ClearConsoleAndWrite("Please enter the amount of fuel you would like to refuel:"); checkForValidAmountOfFuel(Console.ReadLine()); ConsoleUtils.ClearConsoleAndWrite("Please enter the type of fuel type of the vehicle:"); Console.WriteLine(@"1. Soler 2. Octan95 3. Octan96 4. Octan98"); this.m_FuelType = checkForValidFuelType(Console.ReadLine()); } }
private void getNewFuelRateFromUser() { float fuelToAdd = 0; Screen.Clear(); Console.WriteLine("Enter vehicle's license number:"); string licenseNumberToAddFuel = Console.ReadLine(); Fuel.eFuelType fuelType = getFuelTypeFromUser(); Console.WriteLine("Please enter amount of fuel to add:"); bool inputValid = float.TryParse(Console.ReadLine(), out fuelToAdd); if (inputValid == false) { throw new FormatException(); } try { r_Garage.AddFuel(licenseNumberToAddFuel, fuelType, fuelToAdd); Screen.Clear(); Console.WriteLine("{2} {0} Added successfully to Vehicle #{1} ", fuelType.ToString(), licenseNumberToAddFuel, fuelToAdd); } catch (MissingVehicleException ex) { Screen.Clear(); Console.WriteLine("{0}", Environment.NewLine); Console.WriteLine("{0}", ex.Message); Console.WriteLine("{0}", Environment.NewLine); } catch (EngineTypeException ex) { Screen.Clear(); Console.WriteLine("{0}", Environment.NewLine); Console.WriteLine("{0}", ex.Message); Console.WriteLine("{0}", Environment.NewLine); } catch (FuelTypeException ex) { Screen.Clear(); Console.WriteLine("{0}", Environment.NewLine); Console.WriteLine("{0}", ex.Message); Console.WriteLine("{0}", Environment.NewLine); } }
public void AddFuel(string i_VehicleLicenseNumber, Fuel.eFuelType i_FuelType, float i_FuelAmountToAdd) { VehicleInGarage vehicleInGarage = IsExistsInGarage(i_VehicleLicenseNumber); if (vehicleInGarage == null) { throw new MissingVehicleException(i_VehicleLicenseNumber); } else if (vehicleInGarage.Vehicle.EngineType is Battery) { throw new EngineTypeException(); } else if (!vehicleInGarage.Vehicle.FuelValidationType(i_FuelType)) { throw new FuelTypeException(); } vehicleInGarage.Vehicle.EngineType.AddEnergy(i_FuelAmountToAdd); }
/** * This method refuels a fuel based vehicle * Throws ArgumentException if car is not in garage or car is electric based */ public void RefuelVehicle(string i_LicenseNumber, Fuel.eFuelType i_FuelType, 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 Fuel)) { throw new ArgumentException("The Vehicle is not a fuel based vehicle "); } Fuel tank = (Fuel)vehicle.EnergySource; tank.RefuelFuel(i_FuelType, i_AmountToFill); vehicle.SetEnergyPercentage(); }
public void FillFuel(string i_LicenseNumber, Fuel.eFuelType i_FuelType, float i_AmountOfFuel) { if (!checkIfExist(i_LicenseNumber)) { throw new Exception("The vehicle was not found."); } foreach (RegistrationForm costumer in r_CostumerDetail) { if (costumer.Vehicle.LicenseNumber == i_LicenseNumber) { if (costumer.Vehicle.EnergyStorage is Fuel) { costumer.Vehicle.FillEnergyStorage(i_AmountOfFuel, i_FuelType); break; } throw new ArgumentException("Error: This is electric vehicle"); } } }
private void refuelVehicle() { string licenseNumber = r_UI.GetLicenseNumber(); Fuel.eFuelType fuelType = r_UI.GetFuelType(Fuel.GetFuelTypeOptions()); float fuelToAdd = r_UI.GetEnergyToAdd(k_Fuel); try { r_Garage.RefuelVehicleByLicense(licenseNumber, fuelType, fuelToAdd); r_UI.PrintMessage("The refuel succeeded"); } catch (ValueOutOfRangeException ex) { r_UI.PrintRangeMsgError(ex); } catch (Exception ex) { r_UI.PrintMessage(ex.Message); } }
public static void Refule(string i_LicenseNumber, string i_FuelType, string i_AmountToRefule) { Fuel.eFuelType type = (Fuel.eFuelType) int.Parse(i_FuelType); foreach (Vehicle vehicle in Vehicle.r_VehiclesList) { if (vehicle.PowerSource is Fuel) { if (vehicle.LicenseNumber == i_LicenseNumber) { if ((vehicle.PowerSource as Fuel).FuelType == type) { vehicle.PowerSource.CurrentPowerSourceAmount += float.Parse(i_AmountToRefule); } } } else { throw new ArgumentException(); } } }
private Fuel.eFuelType getFuelTypeFromUser() { Console.WriteLine("Select vehicle's fuel type:{0}1) Octan98 {0}2) Octan96 {0}3) Octan95{0}4) Soler", Environment.NewLine); bool inputValid = int.TryParse(Console.ReadLine(), out int userSelection); if (inputValid == false) { throw new FormatException(); } if (userSelection < 1 || userSelection > 4) { throw new ValueOutOfRangeException(4, 1); } Fuel.eFuelType fuelType = Fuel.eFuelType.Octan95; switch (userSelection) { case 1: fuelType = Fuel.eFuelType.Octan98; break; case 2: fuelType = Fuel.eFuelType.Octan96; break; case 3: fuelType = Fuel.eFuelType.Octan95; break; case 4: fuelType = Fuel.eFuelType.Soler; break; } return(fuelType); }
public static void GetFuelTypeFromUser(out Fuel.eFuelType o_FuelType) { bool validInput = false; int userChoice = 0; StringBuilder userPrompt = new StringBuilder(); userPrompt.Append(" ---------------------------------------" + Environment.NewLine); userPrompt.Append(" Please choose your vehicle's fuel type:" + Environment.NewLine); userPrompt.Append(" 1) Octan95" + Environment.NewLine); userPrompt.Append(" 2) Octan96" + Environment.NewLine); userPrompt.Append(" 3) Octan98" + Environment.NewLine); userPrompt.Append(" 4) Soler" + Environment.NewLine); userPrompt.Append(" ---------------------------------------" + Environment.NewLine); Console.Write(userPrompt + Environment.NewLine); while (validInput == false) { try { validInput = GetValidIntFromUserInRange(out userChoice, 1, 4); } catch (FormatException) { Console.WriteLine("Error: Please enter a number."); } catch (ValueOutOfRangeException ex) { Console.WriteLine("Error: The choice number should be between " + ex.MinValue + " to " + ex.MaxValue); } catch (Exception ex) { Console.WriteLine("Unknown error occured: " + Environment.NewLine + ex.Message + Environment.NewLine); } } o_FuelType = (Fuel.eFuelType)userChoice; }
public void FuelNumberOfLitersToFuelBasedVehicle(string i_VehicleLicenseNumber, string i_TypeOfFuel, float i_LitersOfFuelToFill) { GarageVehicle ownerVehicle = GetGarageVehicleByLicenseNumber(i_VehicleLicenseNumber); try { Fuel.eFuelType fuelType = (Fuel.eFuelType)Enum.Parse(typeof(Fuel.eFuelType), i_TypeOfFuel); } catch (OverflowException ex) { throw new FormatException("Wrong fuel type - possible values are Soler, Octan95, Octan96 or Octan98", ex.InnerException); } Dictionary <string, object> parametersForEnergyCharging = new Dictionary <string, object>(); parametersForEnergyCharging.Add(Energy.k_ValueType, Fuel.k_EnergyType); parametersForEnergyCharging.Add(Energy.k_ValueToAdd, i_LitersOfFuelToFill); parametersForEnergyCharging.Add(Fuel.k_FuelType, i_TypeOfFuel); Fuel ownerFuelTank = (Fuel)ownerVehicle.OwnerVehicle.EnergyType; ownerVehicle.OwnerVehicle.EnergyType.AddEnergy(parametersForEnergyCharging); ownerVehicle.OwnerVehicle.PercentOfEnergyLeft = calculateNewPrecanteOfEnergy(ownerFuelTank.MaxAmountOfEnergy, ownerFuelTank.CurrentAmountOfEnergy); }
public Vehicle(eEnergyType i_EnergyType, string i_LicensePlate, short i_NumberOfWheels, float i_MaxAirPressure, float i_MaxEnergy = 100, Fuel.eFuelType i_FuelType = Fuel.eFuelType.Octan95) { this.LicensePlate = i_LicensePlate; this.ModelName = "None"; EnergyType = i_EnergyType; if (i_EnergyType.Equals(eEnergyType.Fuel)) { this.Energy = new Fuel(i_FuelType, i_MaxEnergy); } else { this.Energy = new Electricty(i_MaxEnergy); } m_Wheels = new List <Wheel>(i_NumberOfWheels); for (short i = 0; i < i_NumberOfWheels; i++) { m_Wheels.Add(new Wheel(i_MaxAirPressure)); } }
public MotorCycle(eEnergyType i_EnergyType, string i_LicensePlate, short i_NumberOfWheels, float i_MaxAirPressure, float i_MaxEnergy, Fuel.eFuelType i_FuelType = Fuel.eFuelType.Octan95) : base(i_EnergyType, i_LicensePlate, i_NumberOfWheels, i_MaxAirPressure, i_MaxEnergy) { this.EngineCapacity = 0; this.LicenseType = eLicenseType.A; }
public void FillVehicleAtGarageWithFuel(string i_LicenseNumber, float i_AmountOfFuelToadd, Fuel.eFuelType i_FuelType) { if (IsVehicleinGarage(i_LicenseNumber)) { Vehicle vehicleInRepair = m_Vehicles[i_LicenseNumber].Vehicle; Fuel fuelToCompare = vehicleInRepair.EnergySource as Fuel; if (fuelToCompare != null) { if (fuelToCompare.FuelType == i_FuelType) { fuelToCompare.Fill(i_AmountOfFuelToadd); vehicleInRepair.SetPrecentageOfEnergy(); } else { throw new ArgumentException("Wrong fuel type!"); } } else { throw new ArgumentException("This vehicle is NOT a fuel vehicle."); } } else { throw new ArgumentException("Couldn't find this license number."); } }
public virtual void FillEnergyStorage(float i_Amount, Fuel.eFuelType i_FuelType) { }
private static Energy createEnergySource(float i_CurrentPercentOfElectricity, float i_MaxTankSize, Fuel.eFuelType i_FuelType) { float currentEnergyLevel = i_CurrentPercentOfElectricity * 1 / 100 * i_MaxTankSize; if (currentEnergyLevel > i_MaxTankSize) { throw new ArgumentException("You entered more fuel than the maximum."); } Energy energyType = createEnergyByType(currentEnergyLevel, i_MaxTankSize, i_FuelType); return(energyType); }
private static Energy createEnergyByType(float i_CurrentEnergyLevel, float i_MaxTankSize, Fuel.eFuelType i_FuelType) { Energy energyType; energyType = new Fuel(i_CurrentEnergyLevel, i_MaxTankSize, i_FuelType); return(energyType); }
public Truck(eEnergyType i_EnergyType, string i_LicensePlate, short i_NumberOfWheels, float i_MaxAirPressure, float i_MaxEnergy, Fuel.eFuelType i_FuelType = Fuel.eFuelType.Soler) : base(i_EnergyType, i_LicensePlate, i_NumberOfWheels, i_MaxAirPressure, i_MaxEnergy, i_FuelType) { this.m_CargoSpace = 0; this.m_MoveHazardMaterial = false; }
public override void FillEnergyStorage(float i_Amount, Fuel.eFuelType i_FuelType) { EnergyStorage.Fill(i_Amount, i_FuelType); m_EnergyPercentage = r_EnergyStorage.CalculatePercentage(); }