コード例 #1
0
        static void Main(string[] args)
        {
            Zoo zoo    = new Zoo();
            int choice = 0;

            do
            {
                ShowMenu();
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Nhap chuong :");
                    int n = int.Parse(Console.ReadLine());
                    for (int i = 0; i < n; i++)
                    {
                        Cage cage = new Cage();
                        cage.Input();
                        zoo.AddCage(cage);
                    }
                    break;

                case 2:
                    Console.WriteLine("Nhap ma chuong can xoa");
                    int maChuong = int.Parse(Console.ReadLine());
                    zoo.RemoveCage(maChuong);
                    break;

                case 3:
                    for (int i = 0; i < zoo.CageList.Count; i++)
                    {
                        Console.WriteLine("Nhap so luong con vat cho chuong co ma {0}", zoo.CageList[i].CageNumber);
                        int soVat = int.Parse(Console.ReadLine());
                        for (int j = 0; j < soVat; j++)
                        {
                            Console.WriteLine("Nhap loai thu \n1. Tiger\n2. Dog \n3. Cat");
                            int    animalType = int.Parse(Console.ReadLine());
                            Animal newAnimal;
                            Console.WriteLine("Nhap ten con vat");
                            string ten = Console.ReadLine();
                            Console.WriteLine("Nhap tuoi con vat");
                            int tuoi = int.Parse(Console.ReadLine());
                            Console.WriteLine("Nhap mo ta");
                            string moTa = Console.ReadLine();
                            switch (animalType)
                            {
                            case 1:
                                newAnimal = new Tiger(ten, tuoi, moTa);
                                break;

                            case 2:
                                newAnimal = new Dog(ten, tuoi, moTa);
                                break;

                            case 3:
                                newAnimal = new Cat(ten, tuoi, moTa);
                                break;

                            default:
                                newAnimal = new Tiger(ten, tuoi, moTa);
                                break;
                            }
                            zoo.CageList[i].AddAnimal(newAnimal);
                        }
                    }
                    break;

                case 4:
                    Console.WriteLine("Nhap vao ma chuong muon xoa con vat");
                    int MaChuong = int.Parse(Console.ReadLine());
                    foreach (Cage c in zoo.CageList)
                    {
                        if (c.CageNumber == MaChuong)
                        {
                            Console.WriteLine("Nhap vao ten con vat");
                            string tenVat = Console.ReadLine();
                            c.RemoveAnimal(tenVat);
                            break;
                        }
                    }
                    break;

                case 5:
                    foreach (Cage c in zoo.CageList)
                    {
                        Console.WriteLine("Danh sach con vat o chuong co ma chuong {0}", c.CageNumber);
                        foreach (Animal anm in c.AnimalList)
                        {
                            anm.Speak();
                            anm.ViewInfo();
                        }
                    }
                    break;

                case 6:
                    return;
                }
            } while (choice != 7);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Zoo zoo = new Zoo();
            int choice;

            Console.WriteLine("ZOO MANAGEMENT SYSTEM");
            Console.WriteLine("1. Add Cage");
            Console.WriteLine("2. Remove Cage");
            Console.WriteLine("3. Add Animal");
            Console.WriteLine("4. Remove Animal");
            Console.WriteLine("5. Iterate Animals");
            Console.WriteLine("6. Exit");
            do
            {
                Console.WriteLine("\nSelect: ");
                choice = Int32.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter the Cage:");
                    int n = int.Parse(Console.ReadLine());
                    for (int i = 0; i < n; i++)
                    {
                        Cage cage = new Cage();
                        cage.CageNum();
                        zoo.AddCage(cage);
                    }
                    Console.WriteLine("You have {0} in Cage List", n);
                    break;

                case 2:
                    Console.WriteLine("Enter the Cage want to remove: ");
                    int rmc = int.Parse(Console.ReadLine());
                    zoo.RemoveCage(rmc);
                    Console.WriteLine("Removed successfully");
                    Console.WriteLine("Now you only have {0} in Cage List", rmc);
                    break;

                case 3:
                    for (int i = 0; i < zoo.CageList.Count; i++)
                    {
                        Console.WriteLine("Enter the number of animal at Cage have the number: {0}", zoo.CageList[i].CageNumber);
                        int s = int.Parse(Console.ReadLine());
                        for (int j = 0; j < s; j++)
                        {
                            Console.WriteLine("Enter the animal type: ");
                            Console.WriteLine("1. Tiger");
                            Console.WriteLine("2. Dog");
                            Console.WriteLine("3. Cat");
                            int    animal = int.Parse(Console.ReadLine());
                            Animal animal1;
                            Console.WriteLine("You select {0}", animal);
                            Console.WriteLine("Enter name of animal: ");
                            string name = Console.ReadLine();
                            Console.WriteLine("Enter age of animal: ");
                            int age = int.Parse(Console.ReadLine());
                            Console.WriteLine("Enter description");
                            string des = Console.ReadLine();
                            switch (animal)
                            {
                            case 1:
                                Console.WriteLine("You just have entered information for the Tiger.");
                                animal1 = new Tiger(name, age, des);
                                break;

                            case 2:
                                Console.WriteLine("You just have entered information for the Dog.");
                                animal1 = new Dog(name, age, des);
                                break;

                            case 3:
                                Console.WriteLine("You just have entered information for the Cat.");
                                animal1 = new Cat(name, age, des);
                                break;

                            default:
                                Console.WriteLine("You just have entered information for the Tiger.");
                                animal1 = new Tiger(name, age, des);
                                break;
                            }
                            zoo.CageList[i].AddAnimal(animal1);
                        }
                    }
                    break;

                case 4:
                    Console.WriteLine("Enter the number of Cage want to delete: ");
                    int del = int.Parse(Console.ReadLine());
                    foreach (Cage c in zoo.CageList)
                    {
                        if (c.CageNumber == del)
                        {
                            Console.WriteLine("Enter the name of animal: ");
                            string name = Console.ReadLine();
                            c.RemoveAnimal(name);
                            break;
                        }
                    }
                    break;

                case 5:
                    foreach (Cage c in zoo.CageList)
                    {
                        Console.WriteLine("List of animal in Cage List:  {0}", c.CageNumber);
                        foreach (Animal animal in c.AnimalList)
                        {
                            animal.ViewInfo();
                            animal.Speak();
                        }
                    }
                    break;

                case 6: return;
                }
            }while (choice != 6);
        }