Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 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. public string Name { get; set; }
  11. public int Capacity { get; set; }
  12. public int Size { get; set; }
  13.  
  14. private List<Fish> fishInPool;
  15.  
  16. public Aquarium(string name, int capacity, int size)
  17. {
  18. this.Name = name;
  19. this.Capacity = capacity;
  20. this.Size = size;
  21. fishInPool = new List<Fish>();
  22. }
  23.  
  24. public void Add(Fish fish)
  25. {
  26. if (fishInPool.Count < Capacity && !fishInPool.Contains(fish))
  27. {
  28. fishInPool.Add(fish);
  29. }
  30. }
  31.  
  32. public bool Remove(string name)
  33. {
  34. Fish findFish = fishInPool.FirstOrDefault(x => x.Name == name);
  35. int index = fishInPool.IndexOf(findFish);
  36. if (index != -1)
  37. {
  38. fishInPool.RemoveAt(index);
  39. return true;
  40. }
  41. return false;
  42. }
  43. public string FindFish(string name)
  44. {
  45. Fish find = fishInPool.FirstOrDefault(x => x.Name == name);
  46. int index = fishInPool.IndexOf(find);
  47. if (index >= 0 && index < fishInPool.Count)
  48. {
  49. return find.ToString().TrimEnd();
  50. }
  51. return null;
  52. }
  53.  
  54. public string Report()
  55. {
  56. var aquariumInfo = new StringBuilder();
  57. aquariumInfo.AppendLine($"Aquarium: {Name} ^ Size: {Size}");
  58. foreach (var item in fishInPool)
  59. {
  60. aquariumInfo.AppendLine(item.ToString());
  61. }
  62. return aquariumInfo.ToString();
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement