コード例 #1
0
        static void Main()
        {
            // Cats
            var    cats = new List <Cat>();
            Kitten femaleCat;

            femaleCat = new Kitten("Loly", 3);
            cats.Add(femaleCat);

            femaleCat = new Kitten("Moly", 12);
            cats.Add(femaleCat);

            femaleCat = new Kitten("Doly", 2);
            cats.Add(femaleCat);

            var    maleCats = new List <TomCat>();
            TomCat maleCat;

            maleCat = new TomCat("Tom", 6);
            cats.Add(maleCat);

            maleCat = new TomCat("Maxuel", 10);
            cats.Add(maleCat);

            maleCat = new TomCat("Muri", 1);
            cats.Add(maleCat);

            // Dogs
            var dogs = new List <Dog>();
            Dog dog;

            dog = new Dog("Sharo", 8, "male");
            dogs.Add(dog);

            dog = new Dog("Pesho", 6, "male");
            dogs.Add(dog);

            dog = new Dog("Kaya", 3, "female");
            dogs.Add(dog);

            // Frogs
            var  frogs = new List <Frog>();
            Frog frog;

            frog = new Frog("Kvaki", 5, "male");
            frogs.Add(frog);

            frog = new Frog("Kvuki", 12, "male");
            frogs.Add(frog);

            frog = new Frog("Kveki", 2, "female");
            frogs.Add(frog);

            Console.WriteLine("Avarage cats age is {0}", cats.Average(c => c.Age));
            Console.WriteLine("Avarage dog age is {0}", dogs.Average(d => d.Age));
            Console.WriteLine("Avarage frog age is {0}", frogs.Average(f => f.Age));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            while (true)
            {
                string   command = Console.ReadLine();
                string[] animals = Console.ReadLine().Split(" ").ToArray();
                string   name    = animals[0];
                int      age     = int.Parse(animals[1]);
                string   gender  = animals[2];

                if (command == "Beast!")
                {
                    break;
                }

                if (string.IsNullOrEmpty(name) || age < 0 || string.IsNullOrEmpty(gender))
                {
                    Console.WriteLine("Invalid input!");
                    continue;
                }


                if (command == "Cat")
                {
                    var cat = new Cat(name, age, gender);
                    Console.WriteLine(cat);
                    Console.WriteLine(cat.ProduceSound());
                }

                else if (command == "Dog")
                {
                    var dog = new Dog(name, age, gender);
                    Console.WriteLine(dog);
                    Console.WriteLine(dog.ProduceSound());
                }
                else if (command == "Frog")
                {
                    var frog = new Frog(name, age, gender);
                    Console.WriteLine(frog);
                    Console.WriteLine(frog.ProduceSound());
                }
                else if (command == "Kittens")
                {
                    var kittens = new Kittens(name, age, gender);
                    Console.WriteLine(kittens);
                    Console.WriteLine(kittens.ProduceSound());
                }
                else if (command == "TomCat")
                {
                    var tomCat = new TomCat(name, age, gender);
                    Console.WriteLine(tomCat);
                    Console.WriteLine(tomCat.ProduceSound());
                }
            }
        }
コード例 #3
0
ファイル: Test.cs プロジェクト: AYankova/Telerik-Academy-HW
        static void Main(string[] args)
        {
            var frog1 = new Frog(25, "jaba1", true);
            var frog2 = new Frog(20, "jaba2", false);
            var frog3 = new Frog(25, "jaba3", true);
            var frog4 = new Frog(20, "jaba4", false);
            var allFrogs=new Frog[]{frog1,frog2,frog3,frog4};

            var dog1 = new Dog(30, "kuche1", true);
            var dog2 = new Dog(30, "kuche2", true);
            var dog3 = new Dog(30, "kuche3", true);
            var allDogs=new Dog[]{dog1,dog2,dog3};

            var randomCat1 = new Cat(5, "random kotka1", false);
            var randomCat2 = new Cat(13, "random kotka2", false);
            var randomCat3 = new Cat(5, "random kotka3",true);
            var allCats=new Cat[]{randomCat1,randomCat2,randomCat3};

            var femaleCat1 = new Kitten(5, "jenska kotka1");
            var femaleCat2 = new Kitten(43, "jenska kotka2");
            var femaleCat3 = new Kitten(56, "jenska kotka3");
            var allFemaleCats=new Kitten[]{femaleCat1,femaleCat2,femaleCat3};

            var maleCat1 = new TomCat(5, "mujka kotka1");
            var maleCat2 = new TomCat(6, "mujka kotka2");
            var maleCat3 = new TomCat(200, "mujka kotka3");
            var allMaleCats=new TomCat[]{maleCat1,maleCat2,maleCat3};

            var frogs = allFrogs.Average(x => x.Age);
            Console.WriteLine("The avergae age of frogs is: {0}",frogs);

            var dogs = allDogs.Average(x => x.Age);
            Console.WriteLine("The avergae age of dogs is: {0}", dogs);

            var cats = allCats.Average(x => x.Age);
            Console.WriteLine("The avergae age of  random cats is: {0}", cats);

            var femaleCats = allFemaleCats.Average(x => x.Age);
            Console.WriteLine("The avergae age of female cats(Kittens) is: {0}", femaleCats);

            var maleCats = allMaleCats.Average(x => x.Age);
            Console.WriteLine("The avergae age of male cats(Tomcats) is: {0}", maleCats);
            Console.WriteLine(randomCat1.MakeSound());
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: nadiahristova/SoftUni
        private static ICollection <Animal> SeedAnimals()
        {
            ICollection <Animal> animals = new List <Animal>();

            var rnd = new Random();

            for (int i = 0; i < 4; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var doggie = new Dog(
                    name,
                    (byte)rnd.Next(0, MaxDogAge),
                    (Gender)rnd.Next(0, Enum.GetNames(typeof(Gender)).Length)
                    );

                animals.Add(doggie);
            }

            for (int i = 0; i < 2; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var kitten = new Kitten(
                    name,
                    (byte)rnd.Next(0, MaxCatAge)
                    );

                animals.Add(kitten);
            }

            for (int i = 0; i < 2; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var tomCat = new TomCat(
                    name,
                    (byte)rnd.Next(0, MaxCatAge)
                    );

                animals.Add(tomCat);
            }

            for (int i = 0; i < 4; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var froggie = new Frog(
                    name,
                    (byte)rnd.Next(0, MAxFrogAge),
                    (Gender)rnd.Next(0, Enum.GetNames(typeof(Gender)).Length)
                    );

                animals.Add(froggie);
            }

            return(animals);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: nadiahristova/OOP
        private static ICollection<Animal> SeedAnimals()
        {
            ICollection<Animal> animals = new List<Animal>();

            var rnd = new Random();

            for (int i = 0; i < 4; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var doggie = new Dog(
                        name,
                        (byte)rnd.Next(0, MaxDogAge),
                        (Gender)rnd.Next(0, Enum.GetNames(typeof(Gender)).Length)
                    );

                animals.Add(doggie);
            }

            for (int i = 0; i < 2; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var kitten = new Kitten(
                        name,
                        (byte)rnd.Next(0, MaxCatAge)
                    );

                animals.Add(kitten);
            }

            for (int i = 0; i < 2; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var tomCat = new TomCat(
                        name,
                        (byte)rnd.Next(0, MaxCatAge)
                    );

                animals.Add(tomCat);
            }

            for (int i = 0; i < 4; i++)
            {
                string name = animalNames[rnd.Next(0, animalNames.Count)];
                animalNames.Remove(name);

                var froggie = new Frog(
                        name,
                        (byte)rnd.Next(0, MAxFrogAge),
                        (Gender)rnd.Next(0, Enum.GetNames(typeof(Gender)).Length)
                    );

                animals.Add(froggie);
            }

            return animals;
        }