Advertisement
svetlyoek

Untitled

Aug 13th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. namespace AquariumAdventure
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. public class Aquarium
  9. {
  10. private List<Fish> fishInPool;
  11.  
  12. public Aquarium(string name, int capacity, int size)
  13. {
  14. this.Name = name;
  15. this.Capacity = capacity;
  16. this.Size = size;
  17. this.fishInPool = new List<Fish>();
  18. }
  19.  
  20. public string Name { get; set; }
  21.  
  22. public int Capacity { get; set; }
  23.  
  24. public int Size { get; set; }
  25.  
  26. public void Add(Fish fish)
  27. {
  28. if (!this.fishInPool.Any(f => f.Name == fish.Name) && this.fishInPool.Count < this.Capacity)
  29. {
  30. this.fishInPool.Add(fish);
  31. }
  32. }
  33.  
  34. public bool Remove(string name)
  35. {
  36. if (this.fishInPool.Any(f => f.Name == name))
  37. {
  38. var fishToRemove = this.fishInPool.FirstOrDefault(f => f.Name == name);
  39.  
  40. this.fishInPool.Remove(fishToRemove);
  41. return true;
  42. }
  43.  
  44. return false;
  45. }
  46.  
  47. public Fish FindFish(string name)
  48. {
  49. var fishToRemove = this.fishInPool.FirstOrDefault(f => f.Name == name);
  50.  
  51. if (this.fishInPool.Contains(fishToRemove))
  52. {
  53. return fishToRemove;
  54. }
  55.  
  56. return null;
  57.  
  58. }
  59.  
  60. public string Report()
  61. {
  62.  
  63. StringBuilder result = new StringBuilder();
  64. result.AppendLine($"Aquarium: {this.Name} ^ Size: {this.Size}");
  65.  
  66. foreach (var fish in this.fishInPool)
  67. {
  68. result.AppendLine(fish.ToString());
  69. }
  70.  
  71. return result.ToString().TrimEnd();
  72. }
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement