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
- {
- List<Fish> fishInPool;
- private string name;
- private int size;
- private int capacity;
- public Aquarium(string name, int capacity, int size)
- {
- Name = name;
- Capacity = capacity;
- Size = size;
- fishInPool = new List<Fish>();
- }
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- public int Capacity
- {
- get { return capacity; }
- set { capacity = value; }
- }
- public int Size
- {
- get { return size; }
- set { size = value; }
- }
- public void Add(Fish fish)
- {
- if (fishInPool.Count<Capacity)
- {
- bool isExist = false;
- foreach (var item in fishInPool)
- {
- if (item.Name == fish.Name)
- {
- isExist = true;
- }
- }
- if (isExist==false)
- {
- fishInPool.Add(fish);
- }
- }
- }
- public bool Remove(string name)
- {
- foreach (var item in fishInPool)
- {
- if (item.Name == name)
- {
- fishInPool.Remove(item);
- return true;
- }
- }
- return false;
- }
- public string FindFish(string name)
- {
- foreach (var item in fishInPool)
- {
- if (item.Name == name)
- {
- return item.ToString().TrimEnd();
- }
- }
- return null;
- }
- public string Report()
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine($"Aquarium: {Name} ^ Size: {Size}");
- foreach (var item in fishInPool)
- {
- sb.AppendLine(item.ToString());
- }
- return sb.ToString().TrimEnd();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement