private static void insertNewVehicle(Garage i_Garage) { Console.WriteLine("Please enter license number:"); string licenseNum = checkIfnotEmpty(Console.ReadLine()); bool alreadyInTheGarage = i_Garage.CheckIfInGarage(licenseNum); if (!alreadyInTheGarage) { Console.WriteLine("Please enter owner's name:"); string ownerName = checkIfnotEmpty(Console.ReadLine()); Console.WriteLine("Please enter owner's number:"); string ownerNumber = checkIfnotEmpty(Console.ReadLine()); Console.WriteLine("Please enter model's name:"); string modelName = checkIfnotEmpty(Console.ReadLine()); VehiclesCreator.VehicleType selectedType = vehicleSelection(i_Garage); Dictionary <string, string> vehicleDictionary = new Dictionary <string, string>(); List <string> vehicleProperties = i_Garage.GetProperties(selectedType); foreach (string property in vehicleProperties) { string toPrint = string.Format("Please enter {0}:", property); Console.WriteLine(toPrint); vehicleDictionary.Add(property, Console.ReadLine()); } vehicleDictionary.Add("Owner name", ownerName); vehicleDictionary.Add("Owner phone", ownerNumber); vehicleDictionary.Add("License number", licenseNum); vehicleDictionary.Add("Model name", modelName); try { Vehicle newVehicle = VehiclesCreator.SelectConstructor(selectedType, vehicleDictionary); i_Garage.AddVehicle(newVehicle, licenseNum); } catch (ArgumentException e) { Console.WriteLine(e.Message); } catch (FormatException e) { Console.WriteLine(e.Message); } catch (ValueOutOfRangeException e) { Console.WriteLine(e.Message); } } else { Console.WriteLine("Your vehicle is already in the garage."); } }
public List <string> getProperties(VehiclesCreator.VehicleType vehicleType) { List <string> properties = new List <string>(); switch (vehicleType) { case VehiclesCreator.VehicleType.ElectricCar: properties.AddRange(Car.GetCarProperties()); properties.AddRange(Electric.GetElectricProperties()); break; case VehiclesCreator.VehicleType.FuelCar: properties.AddRange(Car.GetCarProperties()); properties.AddRange(Fuel.GetFuelProperties()); break; case VehiclesCreator.VehicleType.ElectricBike: properties.AddRange(MotorBike.GetMotorbikeProperties()); properties.AddRange(Electric.GetElectricProperties()); break; case VehiclesCreator.VehicleType.FuelBike: properties.AddRange(MotorBike.GetMotorbikeProperties()); properties.AddRange(Fuel.GetFuelProperties()); break; case VehiclesCreator.VehicleType.Truck: properties.AddRange(Truck.GetTruckProperties()); properties.AddRange(Fuel.GetFuelProperties()); break; } return(properties); }
public static Vehicle SelectConstructor(VehiclesCreator.VehicleType io_TypeOfVehicle, Dictionary <string, string> io_VehicleProperties) { Vehicle newVehicle = null; switch (io_TypeOfVehicle) { case VehicleType.ElectricCar: newVehicle = createNewElectricCar(io_VehicleProperties); break; case VehicleType.FuelCar: newVehicle = createNewFuelCar(io_VehicleProperties); break; case VehicleType.ElectricBike: newVehicle = createNewElectricBike(io_VehicleProperties); break; case VehicleType.FuelBike: newVehicle = createNewFuelBike(io_VehicleProperties); break; case VehicleType.Truck: newVehicle = createNewTruck(io_VehicleProperties); break; } return(newVehicle); }