public string FeedFish(string aquariumName) { IAquarium aquarium = this.aquariums.FirstOrDefault(x => x.Name == aquariumName); aquarium.Feed(); return(String.Format(OutputMessages.FishFed, aquarium.Fish.Count)); }
public string InsertDecoration(string aquariumName, string decorationType) { IDecoration decoration = this.decorations.FindByType(decorationType); if (decoration == null) { throw new InvalidOperationException (string.Format(Utilities.Messages.ExceptionMessages .InexistentDecoration, decorationType)); } IAquarium aquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName); if (aquarium == null) { throw new InvalidOperationException (Utilities.Messages.ExceptionMessages.InvalidAquariumType); } aquarium.AddDecoration(decoration); this.decorations.Remove(decoration); return(string.Format(Utilities.Messages .OutputMessages.EntityAddedToAquarium, decorationType, aquariumName)); }
public Piranha(PointF location, SizeF size, IAquarium aquarium) : base(location, size, aquarium) { Speed = Settings.Piranha.Speed; PushState(Walking, FishState.Walking); Type = FishType.Piranha; }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish = null; if (fishType != "FreshwaterFish" && fishType != "SaltwaterFish") { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } else if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else { fish = new SaltwaterFish(fishName, fishSpecies, price); } IAquarium aquarium = aquariums.FirstOrDefault(x => x.Name == aquariumName); Fish fish1 = fish as Fish; if (fish1.FIshLivingPlace != aquarium.GetType().Name) { return("Water not suitable."); } else { aquarium.AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); } }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price)//todo { IAquarium aquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName); IFish fish = null; if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } else { throw new InvalidOperationException("Invalid fish type."); } if ((fish.GetType().Name.Contains("Freshwater") && aquarium.GetType().Name.Contains("Freshwater")) || (fish.GetType().Name.Contains("Saltwater") && aquarium.GetType().Name.Contains("Saltwater"))) { aquarium.AddFish(fish); return($"Successfully added {fishType} to {aquariumName}."); } else { return("Water not suitable."); } }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { //Posible exception IAquarium aquarium = this.aquariums.First(a => a.Name == aquariumName); IFish fish = null; switch (fishType) { case "FreshwaterFish": fish = new FreshwaterFish(fishName, fishSpecies, price); aquarium.AddFish(fish); return(aquarium.GetType().Name == "FreshwaterAquarium" ? string.Format(OutputMessages.FishAdded, fishType, aquariumName) : OutputMessages.UnsuitableWater); case "SaltwaterFish": fish = new SaltwaterFish(fishName, fishSpecies, price); aquarium.AddFish(fish); return(aquarium.GetType().Name == "SaltwaterAquarium" ? string.Format(OutputMessages.FishAdded, fishType, aquariumName) : OutputMessages.UnsuitableWater); default: throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } }
public string CalculateValue(string aquariumName) { IAquarium aquarium = aquariums.FirstOrDefault(x => x.Name == aquariumName); decimal sum = aquarium.Fish.Sum(x => x.Price) + aquarium.Decorations.Sum(x => x.Price); return(string.Format(OutputMessages.AquariumValue, aquariumName, sum)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish = null; if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } else { throw new InvalidOperationException (ExceptionMessages.InvalidFishType); } IAquarium aquarium = GetAquariumByName(aquariumName); if (((fish is FreshwaterFish) && (aquarium is FreshwaterAquarium)) || ((fish is SaltwaterFish) && (aquarium is SaltwaterAquarium))) { aquarium.AddFish(fish); return(string.Format(OutputMessages .EntityAddedToAquarium, fishType, aquariumName)); } return(OutputMessages.UnsuitableWater); }
public BlueNeon(PointF location, SizeF size, IAquarium aquarium) : base(location, size, aquarium) { Type = FishType.BlueNeon; Speed = Settings.BlueNeon.Speed; PushState(Walking, FishState.Walking); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IAquarium aquarium = aquariums[aquariumName]; IFish fish = null; if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } else if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } if (fish == null) { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } if ((fishType == "SaltwaterFish" && aquarium.GetType().Name == "SaltwaterAquarium") || (fishType == "FreshwaterFish" && aquarium.GetType().Name == "FreshwaterAquarium")) { aquarium.AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); } else { return(OutputMessages.UnsuitableWater); } }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish = null; IAquarium aquarium = aquariums.FirstOrDefault(x => x.Name == aquariumName); if (fishType != nameof(FreshwaterFish) && fishType != nameof(SaltwaterFish)) { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } else { string currentAquariumType = aquarium.GetType().Name; if (fishType == "FreshwaterFish" && currentAquariumType == "FreshwaterAquarium") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType == "SaltwaterFish" && currentAquariumType == "SaltwaterAquarium") { fish = new SaltwaterFish(fishName, fishSpecies, price); } else { return(OutputMessages.UnsuitableWater); } aquarium.AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); } }
public string FeedFish(string aquariumName) { IAquarium aquarium = aquariums.FirstOrDefault(a => a.Name == aquariumName); aquarium.Feed(); return($"Fish fed: {aquarium.Fish.Count}"); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IAquarium aqurium = aquariums.First(a => a.Name == aquariumName); if (fishType == "FreshwaterFish") { if (aqurium.GetType().Name != "FreshwaterAquarium") { throw new InvalidOperationException(OutputMessages.UnsuitableWater); } aqurium.AddFish(new FreshwaterFish(fishName, fishSpecies, price)); } else if (fishType == "SaltwaterFish") { if (aqurium.GetType().Name != "SaltwaterAquarium") { throw new InvalidOperationException(OutputMessages.UnsuitableWater); } aqurium.AddFish(new SaltwaterFish(fishName, fishSpecies, price)); } else { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } return(String.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish; if (fishType == typeof(FreshwaterFish).Name) { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType == typeof(SaltwaterFish).Name) { fish = new SaltwaterFish(fishName, fishSpecies, price); } else { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } IAquarium aquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName); string aquariumType = aquarium.GetType().Name[0].ToString(); string fishTypeFirstLetter = fishType[0].ToString(); if (aquariumType != fishTypeFirstLetter) { return(OutputMessages.UnsuitableWater); } else { aquarium.AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); } }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish; if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } else { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } IAquarium currentAquarium = this.aquariums.FirstOrDefault(a => a.Name == aquariumName); string aquariumType = currentAquarium.GetType().Name; bool isTheRightAquariumForTheRightFish = fishType == "FreshwaterFish" && aquariumType == "FreshwaterAquarium" || fishType == "SaltwaterFish" && aquariumType == "SaltwaterAquarium"; if (isTheRightAquariumForTheRightFish) { currentAquarium.AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fish.GetType().Name, currentAquarium.Name)); } else { return(OutputMessages.UnsuitableWater); } }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { if (fishType != "FreshwaterFish" && fishType != "SaltwaterFish") { throw new InvalidOperationException("Invalid fish type."); } IAquarium aquarium = aquariums.FirstOrDefault(a => a.Name == aquariumName); string aquariumToFish = string.Empty; IFish fish = null; if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); aquariumToFish = "Freshwater"; } else if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); aquariumToFish = "Saltwater"; } if (!aquarium.GetType().Name.Contains(aquariumToFish)) { return("Water not suitable."); } aquarium.AddFish(fish); return($"Successfully added {fish.GetType().Name} to {aquarium.Name}."); }
public string AddAquarium(string aquariumType, string aquariumName) { if (aquariumType != "FreshwaterAquarium" && aquariumType != "SaltwaterAquarium") { throw new InvalidOperationException("Invalid aquarium type."); } IAquarium aquarium = null; switch (aquariumType) { case "FreshwaterAquarium": aquarium = new FreshwaterAquarium(aquariumName); break; case "SaltwaterAquarium": aquarium = new SaltwaterAquarium(aquariumName); break; } if (aquarium.Comfort > aquarium.Capacity) { return("Not enough capacity"); } this.aquariums.Add(aquarium); return($"Successfully added {aquariumType}."); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IAquarium aquarium = aquariums.FirstOrDefault(p => p.Name == aquariumName); IFish fish = null; if (fishType == nameof(FreshwaterFish)) { fish = new FreshwaterFish(fishName, fishSpecies, price); if (aquarium.GetType().Name == nameof(FreshwaterAquarium)) { aquarium.AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); } } else if (fishType == nameof(SaltwaterFish)) { fish = new SaltwaterFish(fishName, fishSpecies, price); if (aquarium.GetType().Name == nameof(SaltwaterAquarium)) { aquarium.AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); } } else { throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidFishType)); } return(string.Format(OutputMessages.UnsuitableWater)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish = null; if (fishType == nameof(FreshwaterFish)) { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType == nameof(SaltwaterFish)) { fish = new SaltwaterFish(fishName, fishSpecies, price); } else { throw new InvalidOperationException("Invalid fish type."); } IAquarium aquarium = aquariums.FirstOrDefault(a => a.Name == aquariumName); if (fish.GetType().Name.StartsWith("Fresh") && aquarium.GetType().Name.StartsWith("Fresh") || fish.GetType().Name.StartsWith("Salt") && aquarium.GetType().Name.StartsWith("Salt")) { aquarium.AddFish(fish); return($"Successfully added {fishType} to {aquariumName}."); } else { return($"Water not suitable."); } }
public object Create(params object[] value) { IAquarium aquarium = null; string aquariumType = value[0].ToString(); string aquariumName = value[1].ToString(); if (aquariumType == "FreshwaterAquarium" || aquariumType == "SaltwaterAquarium") { if (aquariumType == "FreshwaterAquarium") { aquarium = new FreshwaterAquarium(aquariumName); } if (aquariumType == "SaltwaterAquarium") { aquarium = new SaltwaterAquarium(aquariumName); } return(aquarium); } throw new InvalidOperationException(ExceptionMessages.InvalidAquariumType); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IAquarium aquarium = shopAquariums.FirstOrDefault(el => el.Name == aquariumName); IFish fish = null; if (fishType != "FreshwaterFish" && fishType != "SaltwaterFish") { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } if ((fishType == "FreshwaterFish" && aquarium.GetType().Name != "FreshwaterAquarium") || (fishType == "SaltwaterFish" && aquarium.GetType().Name != "SaltwaterAquarium")) { return(OutputMessages.UnsuitableWater); } if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); shopAquariums.FirstOrDefault(el => el.Name == aquariumName).AddFish(fish); } else { fish = new SaltwaterFish(fishName, fishSpecies, price); shopAquariums.FirstOrDefault(el => el.Name == aquariumName).AddFish(fish); } //return string.Format(OutputMessages.SuccessfullyAdded, fishType, aquariumName); return($"Successfully added {fishType} to {aquariumName}."); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { if (fishType != nameof(SaltwaterFish) && fishType != nameof(FreshwaterFish)) { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } IAquarium aquarium = this.aquaria.First(x => x.Name == aquariumName); if (aquarium.GetType().Name == nameof(SaltwaterAquarium) && fishType == nameof(FreshwaterFish) || aquarium.GetType().Name == nameof(FreshwaterAquarium) && fishType == nameof(SaltwaterFish)) { return(string.Format(OutputMessages.UnsuitableWater)); } if (fishType == nameof(FreshwaterFish)) { aquarium.AddFish(new FreshwaterFish(fishName, fishSpecies, price)); } else { aquarium.AddFish(new SaltwaterFish(fishName, fishSpecies, price)); } return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish; if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } else if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else { throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidFishType)); } IAquarium aquarium = this.aquariums.FirstOrDefault(x => x.Name == aquariumName); if (aquarium.GetType().Name == "FreshwaterAquarium" && fish.GetType().Name == "SaltwaterFish" || aquarium.GetType().Name == "SaltwaterAquarium" && fish.GetType().Name == "FreshwaterFish") { return(string.Format(OutputMessages.UnsuitableWater)); } else { aquarium.AddFish(fish); } return(string.Format(OutputMessages.FishAdded, fishType, aquariumName)); }
public string FeedFish(string aquariumName) { IAquarium aquarium = aquariums.First(a => a.Name == aquariumName); aquarium.Feed(); return(String.Format(OutputMessages.FishFed, aquarium.Fish.Count)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { if (fishType != "FreshwaterFish" && fishType != "SaltwaterFish") { throw new InvalidOperationException("Invalid fish type."); } IFish fish = null; if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } IAquarium aquarium = this.aquariums.Where(x => x.Name == aquariumName).FirstOrDefault(); if (aquarium.GetType().Name.Contains("Fresh") && fish.GetType().Name.Contains("Fresh")) { aquarium.AddFish(fish); } else if (aquarium.GetType().Name.Contains("Salt") && fish.GetType().Name.Contains("Salt")) { aquarium.AddFish(fish); } else { return($"Water not suitable."); } return($"Successfully added {fish.GetType().Name} to {aquariumName}."); }
public string FeedFish(string aquariumName) { IAquarium wantedAquarium = aquariums.FirstOrDefault(a => a.Name == aquariumName); wantedAquarium.Feed(); return(String.Format(OutputMessages.FishFed, wantedAquarium.Fish.Count)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish = null; if (fishType.ToLower() == "freshwaterfish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } else if (fishType.ToLower() == "saltwaterfish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } if (fish == null) { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } if (!aquariums.ContainsKey(aquariumName)) { throw new InvalidOperationException(ExceptionMessages.InvalidAquariumName); } IAquarium aquarium = this.aquariums[aquariumName]; if (fishType.ToLower() == "saltwaterfish" && aquarium.GetType().Name.ToLower() == "freshwateraquarium") { return(OutputMessages.UnsuitableWater); } else if (fishType.ToLower() == "freshwaterfish" && aquarium.GetType().Name.ToLower() == "saltwateraquarium") { return(OutputMessages.UnsuitableWater); } this.aquariums[aquariumName].AddFish(fish); return(String.Format(OutputMessages.EntityAddedToAquarium, fish.GetType().Name, aquarium.Name)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish; switch (fishType) { case "FreshwaterFish": fish = new FreshwaterFish(fishName, fishSpecies, price); break; case "SaltwaterFish": fish = new SaltwaterFish(fishName, fishSpecies, price); break; default: throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } IAquarium aquarium = aquariums.First(a => a.Name == aquariumName); if (!fishType.StartsWith(aquarium.GetType().Name[0])) { return(OutputMessages.UnsuitableWater); } aquariums.First(a => a.Name == aquariumName).AddFish(fish); return(string.Format(OutputMessages.EntityAddedToAquarium, fishType, aquariumName)); }
public string AddFish(string aquariumName, string fishType, string fishName, string fishSpecies, decimal price) { IFish fish = null; if (fishType == "FreshwaterFish") { fish = new FreshwaterFish(fishName, fishSpecies, price); } if (fishType == "SaltwaterFish") { fish = new SaltwaterFish(fishName, fishSpecies, price); } if (fish == null) { throw new InvalidOperationException(ExceptionMessages.InvalidFishType); } IAquarium seachedAqua = aquariums.FirstOrDefault(a => a.Name == aquariumName); if (seachedAqua.GetType().Name == "SaltwaterAquarium" && fishType == "FreshwaterFish") { return($"Water not suitable."); } if (seachedAqua.GetType().Name == "FreshwaterAquarium" && fishType == "SaltwaterFish") { return($"Water not suitable."); } seachedAqua.AddFish(fish); return($"Successfully added {fishType} to {aquariumName}."); }
public string FeedFish(string aquariumName) { IAquarium seachedAqua = aquariums.FirstOrDefault(a => a.Name == aquariumName); seachedAqua.Feed(); return($"Fish fed: {seachedAqua.Fish.Count}"); }
public MainForm(IAquarium aquariumModel) { InitializeComponent(); _aquariumModel = aquariumModel; _aquariumModel.UnhandledError += HandleException; aquariumControl.Init(_aquariumModel); }
public void Init(IAquarium aquarium) { if (aquarium == null) throw new ArgumentNullException("aquarium"); _aquarium = aquarium; _aquarium.ModelUpdated += HandleModelUpdated; RefreshSize(); }