holllowknight

ДЗ Аквариум

Apr 6th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7.  
  8. namespace Aqua
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Aquarium aquarium = new Aquarium();
  15.             bool runProgram = true;
  16.  
  17.             while (runProgram)
  18.             {
  19.                 Thread.Sleep(1000);
  20.                 Console.Write('S');
  21.                 if (Console.KeyAvailable)
  22.                 {
  23.                     ConsoleKeyInfo key = Console.ReadKey(true);
  24.                     switch (key.Key)
  25.                     {
  26.                         case ConsoleKey.D0:
  27.                             break;
  28.                         case ConsoleKey.I:
  29.                             Console.WriteLine("Введите вид рыбы, которую хотите добавить ");
  30.                             int speciesIndex = Convert.ToInt32(Console.ReadLine());
  31.                             aquarium.AddFish(Fisher.OrderFish(speciesIndex));
  32.                             break;
  33.                         case ConsoleKey.R:
  34.                             Console.WriteLine("Введите номер рыбы, которую необходимо убрать ");
  35.                             int fishIndex = Convert.ToInt32(Console.ReadLine());
  36.                             aquarium.RemoveFish(fishIndex);
  37.                             break;
  38.                         case ConsoleKey.E:
  39.                             runProgram = false;
  40.                             break;
  41.                     }
  42.                 }
  43.             }
  44.  
  45.         }
  46.  
  47.         static class Fisher
  48.         {
  49.             private static string[] _speciesName = new string[] {
  50.                 "Окунь", "Сом", "Анчоус"
  51.                 };
  52.             private static int[] _speciesAge = new int[] { 10, 20, 12 };
  53.  
  54.             public static Fish OrderFish(int speciesIndex)
  55.             {
  56.                 int age;
  57.                 int maxAge;
  58.                 Random rand = new Random();
  59.  
  60.                 maxAge = _speciesAge[speciesIndex];
  61.                 age = rand.Next(maxAge);
  62.                 return new Fish(_speciesName[speciesIndex], age, maxAge);
  63.             }
  64.  
  65.         }
  66.  
  67.         class Fish
  68.         {
  69.             private int _age;
  70.             private int _maxAge;
  71.             private string _speciesName;
  72.             public Fish(string speciesName, int age, int maxAge)
  73.             {
  74.                 _speciesName = speciesName;
  75.                 _age = age;
  76.                 _maxAge = maxAge;
  77.             }
  78.         }
  79.  
  80.         class Aquarium
  81.         {
  82.             private Fish[] _fishes;
  83.  
  84.             public Aquarium()
  85.             {
  86.                 _fishes = new Fish[] { };
  87.             }
  88.  
  89.             public void AddFish(Fish fish)
  90.             {
  91.  
  92.             }
  93.  
  94.             public void RemoveFish(int fishIndex)
  95.             {
  96.  
  97.             }
  98.  
  99.             public void ShowInfo()
  100.             {
  101.  
  102.             }
  103.         }
  104.     }
  105. }
Add Comment
Please, Sign In to add comment