public string CreateMotorcycle(string type, string model, int horsePower) { if (motorcycleRepository.GetByName(model) != null) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } IMotorcycle motorcycle; if (type == "Power") { motorcycle = new PowerMotorcycle(model, horsePower); motorcycleRepository.Add(motorcycle); message = string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model); } else if (type == "Speed") { motorcycle = new SpeedMotorcycle(model, horsePower); motorcycleRepository.Add(motorcycle); message = string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model); } return(message); }
public string CreateMotorcycle(string type, string model, int horsePower) { Motorcycle motorcycle = null; switch (type) { case "SpeedMotorcycle": motorcycle = new SpeedMotorcycle(model, horsePower); break; case "PowerMotorcycle": motorcycle = new PowerMotorcycle(model, horsePower); break; } if (motorcycle == motors.GetByName(model)) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } else { return(string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, model)); } }