Advertisement
Guest User

Untitled

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