Esempio n. 1
0
        public void SameWeightCount(Zoo zoo, int weight)
        {
            Animal[] animals = zoo.getZoo();
            int      count   = 0;

            for (int i = 0; i < animals.Length; i++)
            {
                int a = animals[i].Weight;
                if (animals[i].Weight == weight)
                {
                    count++;
                }
            }
            Console.WriteLine($"В зоопарке {count} животных с весом {weight} ");
        }
Esempio n. 2
0
        public void YearSort(Zoo zoo)
        {
            Animal[] animalarray = zoo.getZoo();
            Animal   temp;

            for (int i = 0; i < animalarray.Length - 1; i++)
            {
                for (int j = i + 1; j < animalarray.Length; j++)
                {
                    if (animalarray[i].Yearofbirth > animalarray[j].Yearofbirth)
                    {
                        temp           = animalarray[i];
                        animalarray[i] = animalarray[j];
                        animalarray[j] = temp;
                    }
                }
            }
            foreach (var item in animalarray)
            {
                Console.WriteLine(item.Print());
            }
        }