Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace AquariumAdventure
- {
- public class Aquarium
- {
- public string Name { get; set; }
- public int Capacity { get; set; }
- public int Size { get; set; }
- private List<Fish> fishInPool;
- public Aquarium(string name, int capacity, int size)
- {
- this.Name = name;
- this.Capacity = capacity;
- this.Size = size;
- fishInPool = new List<Fish>();
- }
- public void Add(Fish fish)
- {
- if (fishInPool.Count < Capacity && !fishInPool.Contains(fish))
- {
- fishInPool.Add(fish);
- }
- }
- public bool Remove(string name)
- {
- Fish findFish = fishInPool.FirstOrDefault(x => x.Name == name);
- int index = fishInPool.IndexOf(findFish);
- if (index != -1)
- {
- fishInPool.RemoveAt(index);
- return true;
- }
- return false;
- }
- public string FindFish(string name)
- {
- Fish find = fishInPool.FirstOrDefault(x => x.Name == name);
- int index = fishInPool.IndexOf(find);
- if (index >= 0 && index < fishInPool.Count)
- {
- return find.ToString().TrimEnd();
- }
- return null;
- }
- public string Report()
- {
- var aquariumInfo = new StringBuilder();
- aquariumInfo.AppendLine($"Aquarium: {Name} ^ Size: {Size}");
- foreach (var item in fishInPool)
- {
- aquariumInfo.AppendLine(item.ToString());
- }
- return aquariumInfo.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement