public string CreateMotorcycle(string type, string model, int horsePower) { //Create a motorcycle with the provided model and horsepower and add it to the repository. //There are two types of motorcycles: "SpeedMotorcycle" and "PowerMotorcycle". IMotorcycle getMotorcycle = this.motorcycleRepository .GetByName(model); //If the motorcycle already exists in the appropriate repository throw an ArgumentException with following message: //"Motorcycle {model} is already created." if (getMotorcycle != null) { throw new ArgumentException( string.Format( ExceptionMessages.MotorcycleExists, model)); } IMotorcycle motorcycle = this.motorcycleFactory .CreateMotorcycle(type, model, horsePower); this.motorcycleRepository.Add(motorcycle); //If the motorcycle is successfully created, the method should return the following message: string result = string.Format( OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, model); return(result); }
} // TODO: Repair public string CreateMotorcycle(string type, string model, int horsePower) { IMotorcycle motorcycle = null; if (type == "Speed") { motorcycle = new SpeedMotorcycle(model, horsePower); } else if (type == "Power") { motorcycle = new PowerMotorcycle(model, horsePower); } foreach (var m in motorcycles.GetAll()) { if (m.Model == motorcycle.Model) { throw new ArgumentException($"Motorcycle {m.Model} is already created."); } } motorcycles.Add(motorcycle); return(string.Format(OutputMessages.RiderCreated, motorcycle.GetType().Name, motorcycle.Model)); }
public string AddMotorcycleToRider(string riderName, string motorcycleModel) { IRider rider = this.riderRepository .GetByName(riderName); if (rider == null) { throw new InvalidOperationException( string.Format( ExceptionMessages.RiderNotFound, riderName)); } IMotorcycle motorcycle = this.motoRepository .GetByName(motorcycleModel); if (motorcycle == null) { throw new InvalidOperationException( string.Format( ExceptionMessages.MotorcycleNotFound, motorcycleModel)); } rider.AddMotorcycle(motorcycle); return(string.Format( OutputMessages.MotorcycleAdded, riderName, motorcycleModel)); }
public IMotorcycle CreateMotorcycle(string type, string model, int horsePower) { Assembly assembly = Assembly .GetCallingAssembly(); Type classType = assembly .GetTypes() .Where(t => t.Name.StartsWith(type) && !t.IsAbstract) .FirstOrDefault(); if (classType == null) { throw new ArgumentException("The Type Motorcycle is not valid!"); } IMotorcycle motorcycle = null; try { motorcycle = (IMotorcycle)Activator .CreateInstance(classType, model, horsePower); } catch (TargetInvocationException tie) { throw new ArgumentException(tie.InnerException.Message); } return(motorcycle); }
public static string MotorcycleSpecificInfo(IMotorcycle motorcycle) { var sb = new StringBuilder(); sb.AppendLine($" Category: {motorcycle.Category}"); return(sb.ToString().TrimEnd()); }
public string CreateMotorcycle(string type, string model, int horsePower) { bool isExist = this.motorcycleRepository .GetAll() .Any(m => m.Model == model); if (isExist) { throw new ArgumentException( string.Format( ExceptionMessages.MotorcycleExists, model)); } IMotorcycle motorcycle = this.motorcycleFactory .CreateMotorcycle(type, model, horsePower); this.motorcycleRepository.Add(motorcycle); string result = string.Format( OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, model); return(result); }
public string CreateMotorcycle(string type, string model, int horsePower) { //Create a motorcycle with the provided model and horsepower and add it to the repository. //There are two types of motorcycles: "SpeedMotorcycle" and "PowerMotorcycle". //If the motorcycle already exists in the appropriate repository throw an ArgumentException with following message: //"Motorcycle {model} is already created." //If the motorcycle is successfully created, the method should return the following message: //"{"SpeedMotorcycle"/ "PowerMotorcycle"} {model} is created." IMotorcycle motorcycle = this.motorcycleRepository .GetByName(model); if (motorcycle != null) { throw new ArgumentException( $"Motorcycle {model} is already created."); } if (type == "Speed") { motorcycle = new SpeedMotorcycle(model, horsePower); } else if (type == "Power") { motorcycle = new PowerMotorcycle(model, horsePower); } this.motorcycleRepository.Add(motorcycle); return($"{motorcycle.GetType().Name} {model} is created."); }
public string CreateMotorcycle(string type, string model, int horsePower) { IMotorcycle motorcycle = this.motorcycleFactory .CreateMotorcycle(type, model, horsePower); IMotorcycle getMotorcycle = this.motoRepository .GetByName(model); if (getMotorcycle == null) { this.motoRepository.Add(motorcycle); } else { throw new ArgumentException( string.Format( ExceptionMessages.MotorcycleExists, model)); } //if (type == "Speed") //{ // motorcycle = new SpeedMotorcycle(model, horsePower); //} //else if (type == "Power") //{ // motorcycle = new PowerMotorcycle(model, horsePower); //} return(string.Format( OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, model)); }
public string CreateMotorcycle(string type, string model, int horsePower) { IMotorcycle moto = null; if (type == "Speed") { moto = new SpeedMotorcycle(model, horsePower); } else if (type == "Power") { moto = new PowerMotorcycle(model, horsePower); } else { throw new ArgumentException(ExceptionMessages.MotorcycleInvalid); } var getAll = this.motoRepository.GetByName(model); if (getAll != null) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } this.motoRepository.Add(moto); return(string.Format(OutputMessages.MotorcycleCreated, moto.GetType().Name, model)); }
public string CreateMotorcycle(string type, string model, int horsePower) { if (this.motorcycleRepository.GetByName(model) != null) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } IMotorcycle motorcycle = null; switch (type) { case "Power": motorcycle = new PowerMotorcycle(model, horsePower); break; case "Speed": motorcycle = new SpeedMotorcycle(model, horsePower); break; default: break; } this.motorcycleRepository.Add(motorcycle); return(string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model)); }
public string CreateMotorcycle(string type, string model, int horsePower) { //Could have an issue with the getbyname method IMotorcycle motorcycle = null; if (type.ToLower() == "speed") { motorcycle = new SpeedMotorcycle(model, horsePower); } else if (type.ToLower() == "power") { motorcycle = new PowerMotorcycle(model, horsePower); } if (motorcycleRepository.GetByName(motorcycle.Model) != null) { throw new ArgumentException($"Motorcycle {motorcycle.Model} is already created."); } else { motorcycleRepository.Add(motorcycle); return($"{motorcycle.GetType().Name} {motorcycle.Model} is created."); } }
public IMotorcycle CreateMotorcycle(string type, string model, int horsePower) { var motorcycleType = Assembly .GetCallingAssembly() .GetTypes() .Where(x => x.Name.StartsWith(type) && !x.IsAbstract) .FirstOrDefault(); if (motorcycleType == null) { throw new ArgumentException("Invalid Motorcycle Type!"); } var parameters = new object[] { model, horsePower }; IMotorcycle motorcycle = null; try { motorcycle = (IMotorcycle)Activator.CreateInstance(motorcycleType, parameters); } catch (TargetInvocationException ex) { throw new ArgumentException(ex.InnerException.Message); } return(motorcycle); }
public void AddMotorcycle(IMotorcycle motorcycle) { // TODO this.Motorcycle = motorcycle ?? throw new ArgumentNullException( nameof(motorcycle), ExceptionMessages.MotorcycleInvalid); }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle == null) { throw new ArgumentNullException(ExceptionMessages.MotorcycleInvalid); } this.Motorcycle = motorcycle; }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle == null) { throw new ArgumentNullException("Motorcycle cannot be null."); } this.Motorcycle = motorcycle; }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle == null) { canParticipate = false; throw new ArgumentException(ExceptionMessages.MotorcycleInvalid); } this.motorcycle = motorcycle; }
public string AddMotorcycleToRider(string riderName, string motorcycleModel) { IRider rider = riders.GetByName(riderName); IMotorcycle motorcycle = motorcycles.GetByName(motorcycleModel); rider.AddMotorcycle(motorcycle); return(string.Format(OutputMessages.MotorcycleAdded, rider.Name, motorcycle.Model)); }
public string AddMotorcycleToRider(string riderName, string motorcycleModel) { IRider rider = CheckIfRiderExists(riderName); IMotorcycle motorcycle = CheckIfMotorExists(motorcycleModel); rider.AddMotorcycle(motorcycle); return(string.Format(OutputMessages.MotorcycleAdded, riderName, motorcycleModel)); }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle is null) { throw new ArgumentNullException(ExceptionMessages.NullMotorException); } this.Motorcycle = motorcycle; this.canParticipate = true; }
public string AddMotorcycleToRider(string riderName, string motorcycleModel) { IRider rider = riderRepository.GetByName(riderName); IMotorcycle motorcycle = motorcycleRepository.GetByName(motorcycleModel); rider.AddMotorcycle(motorcycle); return($"{string.Format(OutputMessages.MotorcycleAdded, riderName, motorcycleModel)}"); }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle == null) { throw new ArgumentNullException(ExceptionMessages.MotorcycleMustBeNull); } this.Motorcycle = motorcycle; this.CanParticipate = true; }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle == null) { throw new ArgumentException("Motorcycle cannot be null."); } Motorcycle = motorcycle; CanParticipate = true; }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle == null) { throw new ArgumentNullException(string.Format(ExceptionMessages.MotorcycleInvalid)); } this.Motorcycle = motorcycle; this.CanParticipate = true; }
public void AddMotorcycle(IMotorcycle motorcycle) { if (motorcycle == null) { throw new ArgumentException(ExceptionMessages.MotorcycleInvalid); } Motorcycle = motorcycle; CanParticipate = true; }
public IMotorcycle CreateMotorcycle(string type, string model, int horsePower) { Type motorcycleType = Assembly .GetCallingAssembly() .GetTypes() .FirstOrDefault(t => t.Name == type + "Motorcycle"); IMotorcycle motorcycle = (IMotorcycle)Activator.CreateInstance(motorcycleType, model, horsePower); return(motorcycle); }
private void setMotorcycle(IMotorcycle i_Motorcycle) { i_Motorcycle.LicenseType = (eLicenseType)Enum.Parse(typeof(eLicenseType), GetLicenseType()); int engineVolume = -1; while (engineVolume <= 0) { engineVolume = int.Parse(GetEngineVolume()); } i_Motorcycle.EngineVolume = engineVolume; }
// ----------------------------------------------------------------------------- // Public Methods public void Update(IMotorcycle motorcycle, int position) { HideSwipeButtons(false); if (motorcycle == null) { return; } _id = motorcycle.Id; _titleTextView.Text = motorcycle.ToString(); }
public string CreateMotorcycle(string type, string model, int horsePower) { IMotorcycle motorcycle = this.motorcycleRepository.GetByName(model); if (motorcycle != null) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } motorcycle = this.motorcycleFactory.CreateMotorcycle(type, model, horsePower); this.motorcycleRepository.Add(motorcycle); return(string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model)); }
public string AddMotorcycleToRider(string riderName, string motorcycleModel) { IRider rider = riderRepository.Models.FirstOrDefault(r => r.Name == riderName); IMotorcycle motorcycle = this.motorcycleRepository.Models.FirstOrDefault(m => m.Model == motorcycleModel); if (rider == null) { throw new InvalidOperationException(String.Format(ExceptionMessages.RiderNotFound, riderName)); } if (motorcycle == null) { throw new InvalidOperationException(String.Format(ExceptionMessages.MotorcycleNotFound, motorcycleModel)); } rider.AddMotorcycle(motorcycle); return(String.Format(OutputMessages.MotorcycleAdded, rider.Name, motorcycle.Model)); }
public void AddMotorcycle(IMotorcycle motorcycle) { //This method adds a motorcycle to the rider. //If the motorcycle null, throw ArgumentNullException with message "Motorcycle cannot be null.". //If motorcycle is not null, save it and after that rider can participate to race. if (motorcycle == null) { throw new ArgumentNullException(nameof(motorcycle), ExceptionMessages.MotorcycleInvalid); } else { this.Motorcycle = motorcycle; } }