public static Vehicle CreateVehicle(string i_LicensePlateNumber, eVehiclesTypes i_VehicleType) { Vehicle newVehicle = null; if (i_LicensePlateNumber.Length != 7 && i_LicensePlateNumber.Length != 8) { throw new ArgumentException("ERROR. License plate number should contain 7 or 8 digits."); } if (!Enum.IsDefined(typeof(eVehiclesTypes), i_VehicleType)) { throw new ArgumentException("ERROR. " + i_VehicleType + "is not exist"); } switch (i_VehicleType) { case eVehiclesTypes.ElectricCar: case eVehiclesTypes.FuelCar: { newVehicle = new Car(i_LicensePlateNumber, i_VehicleType); break; } case eVehiclesTypes.ElectricMotorcycle: case eVehiclesTypes.FuelMotorcycle: { newVehicle = new Motorcycle(i_LicensePlateNumber, i_VehicleType); break; } case eVehiclesTypes.Truck: { newVehicle = new Truck(i_LicensePlateNumber); break; } } return(newVehicle); }
public static Vehicle GetVehicle(string i_VehicleType, string i_EngineType, string i_LicensePlate) { Vehicle vehicle = null; eVehiclesTypes vehicleType = (eVehiclesTypes)Enum.Parse(typeof(eVehiclesTypes), i_VehicleType); eEngineTypes engineType = (eEngineTypes)Enum.Parse(typeof(eEngineTypes), i_EngineType); switch (vehicleType) { case eVehiclesTypes.Car: vehicle = new Car(i_LicensePlate, engineType); break; case eVehiclesTypes.Motorcycle: vehicle = new Motorcycle(i_LicensePlate, engineType); break; case eVehiclesTypes.Truck: vehicle = new Truck(i_LicensePlate, engineType); break; } return(vehicle); }