//-----------------------------------------------------------------// private void completeVehicleInformation(ref Vehicle io_Vehicle, VehicleAllocator.eVehicleType i_VehicleType) { List <string> questions = VehicleAllocator.GetQuestionsAboutVehicle(i_VehicleType, io_Vehicle); List <string> answers = this.getAnswersAboutVehicle(questions); bool isWrongAnswer = true; while (isWrongAnswer) { try { VehicleAllocator.SetAnswersAboutVehicle(i_VehicleType, io_Vehicle, answers); isWrongAnswer = false; } catch (Exception exception) { if (exception is FormatException || exception is ValueOutOfRangeException || exception is ArgumentException) { while (exception != null) { Console.Write(exception.Message); answers[int.Parse(exception.Source)] = Console.ReadLine(); exception = exception.InnerException; } } else { throw exception; } } } }
//-----------------------------------------------------------------// public static void SetAnswersAboutVehicle(VehicleAllocator.eVehicleType i_VehicleType, Vehicle i_Vehicle, List <string> i_Answers) { switch (i_VehicleType) { case eVehicleType.ElectricCar: case eVehicleType.FueledCar: (i_Vehicle as Car).SetAnswersToVehicle(i_Answers); break; case eVehicleType.ElectricMotorcycle: case eVehicleType.FueledMotorCycle: (i_Vehicle as Motorcycle).SetAnswersToVehicle(i_Answers); break; case eVehicleType.Truck: (i_Vehicle as Truck).SetAnswersToVehicle(i_Answers); break; } }
//-----------------------------------------------------------------// private void getVehicleInformation(Garage i_Garage) { Console.WriteLine("Adding vehicle to the garage:" + Environment.NewLine); Garage.InformationOfVehicle informationOfVehicle = null; string licenseNumber = this.getLicenseNumberFromUser(); if (i_Garage.VehiclesInTheGarage.TryGetValue(licenseNumber, out informationOfVehicle)) { Console.WriteLine("This license number already exists in the garage, changing state to In Repair"); informationOfVehicle.State = Garage.InformationOfVehicle.eVehicleStateInGarage.InRepair; } else { this.printVehicleMenu(); VehicleAllocator.eVehicleType vehicleType = (VehicleAllocator.eVehicleType) this.getValidInputValueInRange(1, 5); Vehicle newVehicle = VehicleAllocator.AllocateVehicle(vehicleType, licenseNumber); informationOfVehicle = this.fillInformationForVehicle(newVehicle, vehicleType); i_Garage.VehiclesInTheGarage.Add(licenseNumber, informationOfVehicle); Console.WriteLine("Vehicle added to the garage successfully!"); } this.printBackToMenuPause(); }
//-----------------------------------------------------------------// public static List <string> GetQuestionsAboutVehicle(VehicleAllocator.eVehicleType i_VehicleType, Vehicle i_Vehicle) { List <string> questionsList = null; switch (i_VehicleType) { case eVehicleType.ElectricCar: case eVehicleType.FueledCar: questionsList = (i_Vehicle as Car).GetQuestionStrings(); break; case eVehicleType.ElectricMotorcycle: case eVehicleType.FueledMotorCycle: questionsList = (i_Vehicle as Motorcycle).GetQuestionStrings(); break; case eVehicleType.Truck: questionsList = (i_Vehicle as Truck).GetQuestionStrings(); break; } return(questionsList); }
//-----------------------------------------------------------------// private Garage.InformationOfVehicle fillInformationForVehicle(Vehicle i_Vehicle, VehicleAllocator.eVehicleType i_VehicleType) { string ownerPhoneNumber, ownerName, manufactorName; float currentAirPressure, currentEnergyAmount; Console.Write("Please enter the model: "); i_Vehicle.Model = this.getValidStringInputLettersAndNumbers(); Console.Write("Please enter wheels manufactor name: "); manufactorName = this.getValidStringInputLettersAndNumbers(); Console.Write("Please enter wheels current air pressure: "); currentAirPressure = this.getValidInputValueInRange(0, i_Vehicle.Wheels.First().MaxAirPressure); Console.Write("Please enter current energy left in your vehicle: "); if (i_Vehicle.Engine is Engine.FuelEngine) { currentEnergyAmount = getValidInputValueInRange(0, (i_Vehicle.Engine as Engine.FuelEngine).MaxFuelCapacity); } else { currentEnergyAmount = getValidInputValueInRange(0, (i_Vehicle.Engine as Engine.ElectricEngine).MaxBatteryTime); } i_Vehicle.SetVehicleWheels(manufactorName, currentAirPressure); i_Vehicle.SetCurrentEnergyAmount(currentEnergyAmount); i_Vehicle.SetEnergyPrecentage(); this.completeVehicleInformation(ref i_Vehicle, i_VehicleType); this.getOwnerInformation(out ownerName, out ownerPhoneNumber); return(new Garage.InformationOfVehicle(ownerName, ownerPhoneNumber, i_Vehicle)); }