Untitled

 avatar
unknown
plain_text
23 days ago
4.6 kB
1
Indexable
using System;
using System.Diagnostics;
using System.Net.Sockets;
using System.Reflection.Emit;
using Random = System.Random;

namespace MyApp
{
    /****************************(Classes)********************************/

    public abstract class Creature
    {
        public string Name { get; set; }
        public string Type { get; protected set; }

        public Creature(string name)
        {
            Name = name;
        }

        public abstract void Print();
    }

    public class Human : Creature
    {
        public Human(string name) : base(name)
        {
            Type = "Human";
        }

        public override void Print()
        {
            Console.WriteLine($"name : {Name} , Tpye : {Type}");
        }
    }

    public class Fish : Creature
    {
        public Fish(string name) : base(name)
        {
            Type = "Fish";
        }

        public override void Print()
        {
            Console.WriteLine($"name : {Name} , Tpye : {Type}");
        }
    }

    public class Bird : Creature
    {
        public Bird(string name) : base(name)
        {
            Type = "Bird";
        }

        public override void Print()
        {
            Console.WriteLine($"name : {Name} , Tpye : {Type}");
        }
    }

    /********************************************************************/
    internal class Program
    {

        //****************************(Functions)********************************/

        //*******************************************************************/

        static void Main()
        {
            ///****************************(Main Code)********************************/

            

             int ch = 10;

             Creature[] creturnes = new Creature[20];
             Random rand = new Random();
             for (int i = 0; i < 10; ++i)
             {
                 int choice = rand.Next(0, 3);
                 switch (choice)
                 {
                     case 0:
                         creturnes[i] = new Human($"Human , {i + 1}");
                         break;
                     case 1:
                         creturnes[i] = new Fish($"Fish , {i + 1}");
                         break;
                     case 2:
                         creturnes[i] = new Bird($"Bird , {i + 1}");
                         break;
                 }
             }

             while (creturnes[19] == null)
             {
                 Console.WriteLine("select minue : \n" +
                                   "1 - add \n " +
                                   "2 - show \n " +
                                   "3 - remove \n " +
                                   "4 - exist");
                 int choice = int.Parse(Console.ReadLine());
                 switch (choice)
                 {
                     case 1:
                     {
                         Console.WriteLine("select minue : \n" +
                                           "1 - add Human \n " +
                                           "2 - add Fish \n " +
                                           "3 - add Bird \n ");
                         int choice2 = int.Parse(Console.ReadLine());
                         switch (choice2)
                         {
                             case 0:
                                 creturnes[ch] = new Human($"Human , {ch + 1}");
                                 break;
                             case 1:
                                 creturnes[ch] = new Fish($"Fish , {ch + 1}");
                                 break;
                             case 2:
                                 creturnes[ch] = new Bird($"Bird , {ch + 1}");
                                 break;
                         }

                         ch++;
                     }
                         break;
                     case 2:
                     {
                         for(int i = 0;i < ch;i++)
                         {
                             creturnes[i].Print();
                         }
                     }
                         break;
                     case 3:
                     {
                         creturnes[ch] = null;
                         ch--;
                     }
                         break;
                 }
             }
         
 
            //*******************************************************************/
        }

    }
}

Leave a Comment