private static PowerSource.eFuel getValidFuelTypeFromUser() { int numberOfFuelTheUserChose; Console.WriteLine(string.Format( @"Which fuel would you like to use? + 1.Octan 95 2.Octan 96 3.Octan 98 4.Soler")); getValidAnswerToMultyplyChoiceAnswer(out numberOfFuelTheUserChose, 1, 4); PowerSource.eFuel fuelToReturn = PowerSource.eFuel.Octan95; switch (numberOfFuelTheUserChose) { case -1: throw new FormatException("You are back in the main menu"); case 1: fuelToReturn = PowerSource.eFuel.Octan95; break; case 2: fuelToReturn = PowerSource.eFuel.Octan96; break; case 3: fuelToReturn = PowerSource.eFuel.Octan98; break; case 4: fuelToReturn = PowerSource.eFuel.Soler; break; } return(fuelToReturn); }
public bool FillGasInGasVehicle(string i_LicensePlate, PowerSource.eFuel i_TypeOfGass, float i_AmountOfGass) { bool carFound = false; foreach (GarageVehicle garageVehicle in m_Vehicles) { if (garageVehicle.Vehicle.LicensePlate.Equals(i_LicensePlate)) { carFound = true; FuelTank fuelTank = garageVehicle.Vehicle.PowerSource as FuelTank; if (fuelTank == null) { throw new ArgumentException("This vehicle doesn't run on gass"); } else { fuelTank.Charge(i_AmountOfGass, i_TypeOfGass); } break; } } return(carFound); }
private static void toFuelACar(Garage io_Garage) { Console.WriteLine("Please enter the vehicle's License Plate that you would like to fuel "); string licensePlate = Console.ReadLine(); PowerSource.eFuel typeOfGass = getValidFuelTypeFromUser(); Console.WriteLine("Please enter the amount of fuel to add"); float amountOfGasToAdd = getValidPositiveFloatFromUser(); bool isTheCarInTheGarage = io_Garage.FillGasInGasVehicle(licensePlate, typeOfGass, amountOfGasToAdd); hadnleInputCarFoundOrNot(isTheCarInTheGarage, String.Format("Vehicle {0} was fueld!", licensePlate)); }