public string AddBunny(string bunnyType, string bunnyName) { if (bunnyType != "HappyBunny" && bunnyType != "SleepyBunny") { throw new InvalidOperationException("Invalid bunny type."); } if (bunnyType == "HappyBunny") { bunnies.Add(new HappyBunny(bunnyName)); } else { bunnies.Add(new SleepyBunny(bunnyName)); } return($"Successfully added {bunnyType} named {bunnyName}."); }
public string AddBunny(string bunnyType, string bunnyName) { IBunny currentBunny = null; if (bunnyType == "HappyBunny") { currentBunny = new HappyBunny(bunnyName); bunnies.Add(currentBunny); } else if (bunnyType == "SleepyBunny") { currentBunny = new SleepyBunny(bunnyName); bunnies.Add(currentBunny); } else { throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType); } return($"{String.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName)}"); }
public string AddBunny(string bunnyType, string bunnyName) { if (bunnyType != nameof(HappyBunny) && bunnyType != nameof(SleepyBunny)) { throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType); } IBunny bunny; if (bunnyType == nameof(HappyBunny)) { bunny = new HappyBunny(bunnyName); } else { bunny = new SleepyBunny(bunnyName); } bunnies.Add(bunny); return(string.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName)); }
public string AddBunny(string bunnyType, string bunnyName) { IBunny bunny = null; if (bunnyType == "HappyBunny") { bunny = new HappyBunny(bunnyName); } else if (bunnyType == "SleepyBunny") { bunny = new SleepyBunny(bunnyName); } else { throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType); } bunnies.Add(bunny); return($"Successfully added {bunnyType} named {bunnyName}."); }
public string AddBunny(string bunnyType, string bunnyName) //ok? { // Valid types are: "HappyBunny" and "SleepyBunny". if (bunnyType != "HappyBunny" && bunnyType != "SleepyBunny") { throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidBunnyType)); } IBunny bunny = null; if (bunnyType == "HappyBunny") { bunny = new HappyBunny(bunnyName); } else if (bunnyType == "SleepyBunny") { bunny = new SleepyBunny(bunnyName); } bunnies.Add(bunny); return($"Successfully added {bunnyType} named {bunnyName}."); }
public string AddBunny(string bunnyType, string bunnyName) { IBunny bunny = null; switch (bunnyType) { case "HappyBunny": bunny = new HappyBunny(bunnyName); break; case "SleepyBunny": bunny = new SleepyBunny(bunnyName); break; default: throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType); } bunnyRepository.Add(bunny); return(string.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName)); }