Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 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 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.         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.                 this.fishInPool.Add(fish);
  29.             }
  30.         }
  31.         public bool Remove(string name)
  32.         {
  33.             foreach(var fish in this.fishInPool)
  34.             {
  35.                 if (fish.Name == name)
  36.                 {
  37.                     this.fishInPool.Remove(fish);
  38.                     return true;
  39.                 }
  40.             }
  41.             return false;
  42.         }
  43.         public Fish FindFish(string name)
  44.         {
  45.             Fish fish = this.fishInPool.FirstOrDefault(x => x.Name == name);
  46.             return fish;
  47.         }
  48.         public string Report()
  49.         {
  50.             StringBuilder sb = new StringBuilder();
  51.             sb.AppendLine($"Aquarium: {this.Name} ^ Size: {this.Size}");
  52.             foreach(var fish in this.fishInPool)
  53.             {
  54.                 sb.AppendLine(fish.ToString());
  55.             }
  56.             return sb.ToString().Trim();
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement