Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 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.         List<Fish> fishInPool;
  11.  
  12.         private string name;
  13.         private int size;
  14.         private int capacity;
  15.  
  16.         public Aquarium(string name, int capacity, int size)
  17.         {
  18.             Name = name;
  19.             Capacity = capacity;
  20.             Size = size;
  21.  
  22.             fishInPool = new List<Fish>();
  23.         }
  24.  
  25.         public string Name
  26.         {
  27.             get { return name; }
  28.             set { name = value; }
  29.         }
  30.        
  31.         public int Capacity
  32.         {
  33.             get { return capacity; }
  34.             set { capacity = value; }
  35.         }
  36.        
  37.         public int Size
  38.         {
  39.             get { return size; }
  40.             set { size = value; }
  41.         }
  42.  
  43.         public void Add(Fish fish)
  44.         {
  45.             if (fishInPool.Count<Capacity)
  46.             {
  47.                 bool isExist = false;
  48.                 foreach (var item in fishInPool)
  49.                 {
  50.                     if (item.Name == fish.Name)
  51.                     {
  52.                         isExist = true;
  53.                     }
  54.                 }
  55.                 if (isExist==false)
  56.                 {
  57.                     fishInPool.Add(fish);
  58.                 }
  59.             }
  60.         }
  61.  
  62.         public bool Remove(string name)
  63.         {
  64.             foreach (var item in fishInPool)
  65.             {
  66.                 if (item.Name == name)
  67.                 {
  68.                     fishInPool.Remove(item);
  69.                     return true;
  70.                 }
  71.             }
  72.             return false;
  73.         }
  74.  
  75.         public string FindFish(string name)
  76.         {
  77.             foreach (var item in fishInPool)
  78.             {
  79.                 if (item.Name == name)
  80.                 {
  81.                    
  82.                     return item.ToString().TrimEnd();
  83.                 }
  84.             }
  85.             return null;
  86.         }
  87.  
  88.         public string Report()
  89.         {
  90.             StringBuilder sb = new StringBuilder();
  91.             sb.AppendLine($"Aquarium: {Name} ^ Size: {Size}");
  92.             foreach (var item in fishInPool)
  93.             {
  94.                 sb.AppendLine(item.ToString());
  95.             }
  96.             return sb.ToString().TrimEnd();
  97.         }
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement