Пример #1
0
        static void Main(string[] args)
        {
            do
            {
                Console.WriteLine("Select menu program: ");
                Console.WriteLine("1. Create a Crocodile: ");
                Console.WriteLine("2. Create a Cat: ");
                Console.WriteLine("3. Create a Fish: ");
                Console.WriteLine("4. View Terrestrial Animals: ");
                Console.WriteLine("5. View Marine Animals: ");
                Console.WriteLine("6. View All Animals: ");
                Console.WriteLine("7. Delete Animal: ");
                Console.WriteLine("8. Exit: ");
                select = Convert.ToInt32(Console.ReadLine());
                switch (select)
                {
                case 1:
                    Crocodile crocodile = new Crocodile();
                    crocodile.creatCrocodile();
                    iAnimal.Add(crocodile);
                    break;

                case 2:
                    Cat cat = new Cat();
                    cat.creatCat();
                    iAnimal.Add(cat);
                    break;

                case 3:
                    Fish fish = new Fish();
                    fish.creatFish();
                    iAnimal.Add(fish);
                    break;

                case 4:
                    foreach (var item in iAnimal)
                    {
                        if (item is IMarineAnimal)
                        {
                            Console.WriteLine(item.ToString());
                            item.Move();
                        }
                    }

                    break;

                case 5:
                    foreach (var item in iAnimal)
                    {
                        if (item is ITerrestrialAnimal)
                        {
                            Console.WriteLine(item.ToString());
                            item.Move();
                        }
                    }
                    break;

                case 6:
                    foreach (var item in iAnimal)
                    {
                        Console.WriteLine(item.ToString());
                        item.Move();;
                    }
                    break;

                case 7:

                    foreach (var item in iAnimal)
                    {
                        Console.WriteLine(item.ToString());
                    }
                    Console.WriteLine("Nhap ID Animal muon xoa:");
                    int number = Convert.ToInt32(Console.ReadLine());
                    foreach (var item in iAnimal)
                    {
                        if (item.ID == number)
                        {
                            iAnimal.Remove(item);
                            break;
                        }
                    }
                    break;
                }
            } while(select != 8);
        }