Exemplo n.º 1
0
        public static void Main()
        {
            // fluent kittens

            Console.WriteLine("Kittens: ");

            var kitten1 = new Kitten("mishka", "black", "purring", 2);
            var kitten2 = new Kitten()
                          .WithName("mishka")
                          .WithAge(2)
                          .WithColor("black")
                          .WithState("purring");

            Console.WriteLine("kitten 1: " + kitten1);
            Console.WriteLine("kitten 2: " + kitten2);

            // fluent switch

            Console.WriteLine("\nSwitch demo: ");

            // switch arg
            var person = "Gosho";
            // enable/disable fallthrough
            var fallThrough = true;

            new Switch <string>(person, fallThrough)
            .Case("Pesho", () => Console.WriteLine("Pesho e pich"))
            .Case(name => name == "Ivan", () => Console.WriteLine("Ivan e dvoikar"))
            .Case(person.Length == 5, () => Console.WriteLine("Ne go znam koi e, ama imeto mu ima 5 bukvi"))
            .Default(() => Console.WriteLine("default case"));
        }
Exemplo n.º 2
0
        public Kitten Create(string name, int age, Breed breed)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            try
            {
                var kitten = new Kitten()
                {
                    Name  = name,
                    Age   = age,
                    Breed = breed
                };

                this.db.Kittens.Add(kitten);
                this.db.SaveChanges();

                return(kitten);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        static void Main()
        {
            Cat tommy = new Cat("Tommy" ,2 ,Sex.male);
            Dog sharo = new Dog("Sharo" , 3 ,Sex.male);
            Frog princess = new Frog("Afrodita" , 5 , Sex.female);
            Kitten milka = new Kitten("Milka" , 4 , Sex.female);
            TomCat tom = new TomCat("Tom" , 1 , Sex.male);
            zooPark = new Animal[] { tommy, sharo ,princess , milka , tom};    // <-- Is this an abstract ? A: maybe calling a array is possible ...

            foreach (var animal in zooPark)
            {
                Console.WriteLine(animal);
                switch (animal.GetType().Name)
                {
                    case "Dog":
                        Dog doggy = animal as Dog;
                        doggy.Talk();
                        break;
                    case "Cat":
                        Cat catty = animal as Cat;
                        catty.Talk();
                        break;
                    case "Frog":
                        Frog frogie = animal as Frog;
                        frogie.Talk();
                        break;
                    default:
                        break;
                }
            }
            CalculateAverageAge();
            Console.WriteLine("\n\r\n\rTo see that condition for male checking of kitten and TOmcat works");
            // See implemented method below
            CheckSexAnimal();
        }
Exemplo n.º 4
0
        public IActionResult Add(RegisterKittenBindingModel model)
        {
            using (this.Context)
            {
                var breeds = this.Context.Breeds.ToList();

                bool validCatModel = ValidateCatModel(model, breeds);
                if (this.User.IsAuthenticated && validCatModel)
                {
                    Breed breed = this.Context.Breeds.FirstOrDefault(x => x.Name == model.Breed);

                    Kitten kitten = new Kitten()
                    {
                        Name    = model.Name,
                        Age     = int.Parse(model.Age),
                        BreedId = breed.Id,
                        Breed   = breed
                    };

                    breed.Kittens.Add(kitten);

                    this.Context.Kittens.Add(kitten);
                    this.Context.SaveChanges();
                    return(this.Add());
                }
                else if (!validCatModel)
                {
                    return(View());
                }
            }
            this.Model.Data[ErrorKey] = ShowMessageValue;
            this.Model.Data[ErrorKey] = UnauthorizedErrorMessage;

            return(RedirectToAction(LoginRoute));
        }
Exemplo n.º 5
0
    static void Main(string[] args)
    {
        //Create a hierarchy Dog, Frog, Cat, Kitten, Tomcat and define useful
        //constructors and methods. Dogs, frogs and cats are Animals. All animals
        //can produce sound (specified by the ISound interface). Kittens and
        //tomcats are cats. All animals are described by age, name and sex. Kittens
        //can be only female and tomcats can be only male. Each animal produces a specific
        //sound. Create arrays of different kinds of animals and calculate the average
        //age of each kind of animal using a static method (you may use LINQ).

        //Make some animals and test their properties
        Kitten kitty = new Kitten(3, "Kitty");//the sex is aways female
        Console.WriteLine(kitty.Name + "-" + kitty.Age + "-" + kitty.sex);
        kitty.ProduceSound();
        Tomkat tom = new Tomkat(5, "Tom");//the sex is aways male
        Console.WriteLine(tom.Name + "-" + tom.Age + "-" + tom.sex);
        tom.ProduceSound();
        Dog doggy = new Dog(8, "Doggy", Sex.male);
        Console.WriteLine(doggy.Name + "-" + doggy.Age + "-" + doggy.sex);
        doggy.ProduceSound();
        Frog froggy = new Frog(1, "Froggy", Sex.female);
        Console.WriteLine(froggy.Name + "-" + froggy.Age + "-" + froggy.sex);
        froggy.ProduceSound();

        //Make array with diferent animals and calculate the average age for every animal type in the array
        Animal[] animals = {kitty,tom,froggy,doggy,
                                   new Kitten(4,"Keit"),
                                   new Tomkat(5,"Tomas"),
                                   new Dog(11,"Rex",Sex.male),
                                   new Frog(3,"Curmit",Sex.male)};
        CalculateEveryAnimalAverageAge(animals);
    }
Exemplo n.º 6
0
        public IActionResult Add(AddKittenModel model)
        {
            if (!this.User.IsAuthenticated)
            {
                return(this.RedirectToAction("/"));
            }

            if (!this.IsValidModel(model))
            {
                this.Model.Data["error"] = "Invalid kitten data";
            }

            using (this.Context)
            {
                var breed = new Breed()
                {
                    Type = model.Breed
                };
                var kitten = new Kitten()
                {
                    Age   = model.Age,
                    Breed = breed,
                    Name  = model.Name
                };

                this.Context.Add(kitten);
                this.Context.SaveChanges();
            }

            return(this.RedirectToAction("/kittens/all"));
        }
Exemplo n.º 7
0
        public IActionResult Add(AddKittenBindingModel addKittenBindingModel)
        {
            if (!this.IsValidModel(addKittenBindingModel))
            {
                this.Model["error"] = "<h1 class=\"message\">Something went wrong !</h1>";
                return(View());
            }

            using (this.Context)
            {
                var currendbBreed = Context.Breads.FirstOrDefault(b => b.Name == addKittenBindingModel.Breed);

                if (currendbBreed == null)
                {
                    this.Model["error"] = "<h1 class=\"message\">Breed is not valid!</h1>";
                    return(View());
                }

                var kitten = new Kitten()
                {
                    Name    = addKittenBindingModel.Name,
                    Age     = addKittenBindingModel.Age,
                    Breed   = currendbBreed,
                    BreedId = currendbBreed.Id
                };

                currendbBreed.Kittens.Add(kitten);

                Context.Kittens.Add(kitten);

                Context.SaveChanges();

                return(RedirectToAction("/kitten/all"));
            }
        }
Exemplo n.º 8
0
    static void Main()
    {
        Dog dogOne = new Dog("Sharo", "male", 7);
        Dog dogTwo = new Dog("Sara", "female", 17);
        Dog dogThree = new Dog("Tara", "female", 1);
        Dog[] dogArr = new Dog[] { dogOne, dogTwo, dogThree };
        Console.WriteLine("The average age of dogs is {0:F2} years old.", Animal.CalculateAverage(dogArr));
        Console.WriteLine("Dog {0} says {1}.", dogThree.Name, dogThree.PrintSound());

        Frog frogOne = new Frog("Skokla", "female", 23);
        Frog frogTwo = new Frog("Handsome", "male", 9);
        Frog frogThree = new Frog("Skokancho", "male", 2);
        Frog[] frogArr = new Frog[] { frogOne, frogTwo, frogThree };
        Console.WriteLine("The average age of frogs is {0:F2} years old.", Animal.CalculateAverage(frogArr));
        Console.WriteLine("Frog {0} says {1}.", frogThree.Name, frogThree.PrintSound());

        Kitten kittenOne = new Kitten("Hihi", 1);
        Kitten kittenTwo = new Kitten("Kiki", 1);
        Kitten kittenThree = new Kitten("Kenny", 2);
        Kitten[] kittenArr = new Kitten[] { kittenOne, kittenTwo, kittenThree };
        Console.WriteLine("The average age of kittens is {0:F2} years old.", Animal.CalculateAverage(kittenArr));
        Console.WriteLine("Kitten {0} says {1}.", kittenThree.Name, kittenThree.PrintSound());

        Tomcat tomcatOne = new Tomcat("Pancho", 4);
        Tomcat tomcatTwo = new Tomcat("Robby", 3);
        Tomcat tomcatThree = new Tomcat("Vasko", 8);
        Tomcat[] tomcatArr = new Tomcat[] { tomcatOne, tomcatTwo, tomcatThree };
        Console.WriteLine("The average age of tomcats is {0:F2} years old.", Animal.CalculateAverage(tomcatArr));
        Console.WriteLine("Tomcat {0} says {1}.", tomcatThree.Name, tomcatThree.PrintSound());
    }
        public static Animal Create(string animalType, string[] animalInfo)
        {
            Validator.AnimalType(animalType);
            Validator.AnimalInfo(animalInfo);

            string name   = animalInfo[0];
            int    age    = int.Parse(animalInfo[1]);
            string gender = animalInfo[2];

            switch (animalType)
            {
            case "Dog":
                var newDog = new Dog(name, age, gender);
                return(newDog);

            case "Cat":
                var newCat = new Cat(name, age, gender);
                return(newCat);

            case "Frog":
                var newFrog = new Frog(name, age, gender);
                return(newFrog);

            case "Kitten":
                var kitten = new Kitten(name, age, gender);
                return(kitten);

            case "Tomcat":
                var tomcat = new Tomcat(name, age, gender);
                return(tomcat);
            }

            return(null);
        }
Exemplo n.º 10
0
    public static void TestCreatures()
    {
        Dog charlie = new Dog("Charlie", 4, true);

        Console.WriteLine(charlie);
        charlie.ProduceSound();

        Console.WriteLine();

        Frog quackster = new Frog("Rab", 1, false);

        Console.WriteLine(quackster);
        quackster.ProduceSound();

        Console.WriteLine();

        Cat miew = new Cat("Dangleton", 3, false);

        Console.WriteLine(miew);
        miew.ProduceSound();

        Console.WriteLine();

        Kitten kitty = new Kitten("KittyCat", 3);

        Console.WriteLine(kitty);
        kitty.ProduceSound();

        Console.WriteLine();

        Tomcat tom = new Tomcat("Tom", 2);

        Console.WriteLine(tom);
        tom.ProduceSound();
    }
    public static void Main()
    {
        Turtle turtle = new Turtle();
        Console.WriteLine(turtle);
        Console.WriteLine("The {0} can go {1} km/h ", turtle.GetName(), turtle.Speed);

        Console.WriteLine();

        Cheetah cheetah = new Cheetah();
        Console.WriteLine(cheetah);
        Console.WriteLine("The {0} can go {1} km/h ", cheetah.GetName(), cheetah.Speed);

        Console.WriteLine();

        Tomcat tomcat = new Tomcat();
        Console.WriteLine(tomcat);
        Console.WriteLine("The {0} can go {1} km/h ", tomcat.GetName(), tomcat.Speed);
        tomcat.SayMyaau();

        Console.WriteLine();

        Kitten kitten = new Kitten();
        Console.WriteLine(kitten);
        Console.WriteLine("The {0} can go {1} km/h ", kitten.GetName(), kitten.Speed);
        kitten.SayMyaau();

        // This will not compile (Cat is abstract -> cannot be instantiated)
        //Cat cat = new Cat();
    }
Exemplo n.º 12
0
 static void Main()
 {
     //
     Cat somecat = new Cat("Monika_Cat",4,"female");
     somecat.ProduceSound();
     Kitten kitten = new Kitten("Vesi_Kitten", 5);
     kitten.ProduceSound();
     Console.WriteLine(kitten.Sex);
     Tomcat tomCat = new Tomcat("Tomas_TomCat", 6);
     tomCat.ProduceSound();
     Console.WriteLine(tomCat.Sex);
     Frog kyrmit = new Frog("Kyrmit_Jabok", 2, "male");
     Dog rex = new Dog("Rex_Dog", 7, "male");
     Dog hera = new Dog("Hera_Dog", 8, "female");
     List<Animal> animalsList = new List<Animal>();
     Cat lora = new Cat("Lora_Cat", 3, "female");
     animalsList.Add(somecat);
     animalsList.Add(kitten);
     animalsList.Add(tomCat);
     animalsList.Add(kyrmit);
     animalsList.Add(rex);
     animalsList.Add(hera);
     animalsList.Add(lora);
     //Average groups age
     var animalGroups =
         from animal in animalsList
         group animal by animal.GetType();
     foreach (var animals in animalGroups)
     {
         Console.WriteLine(animals.myAverage());
     }
 }
Exemplo n.º 13
0
    public static void Main()
    {
        Dog lol = new Dog("Ivan", 12, Sex.Male);
        lol.MakeSound();

        Kitten test = new Kitten("Ivanka", 12, Sex.Female);

        Animal[] myZoo = 
        {
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
            new Cat("Ivanka", 12, Sex.Female),
            new Kitten("Ivanka", 12, Sex.Female),
            new Frog("Ivanka", 20, Sex.Female),
            new Frog("Ivanka", 10, Sex.Female),
            new Dog("Ivanka", 12, Sex.Female),
        };

        Animal.AgeAverage(myZoo);
    }
Exemplo n.º 14
0
    static void Main(string[] args)
    {
        string type = Console.ReadLine();

        while (type != "Beast!")
        {
            try
            {
                string[] animalInfo   = Console.ReadLine().Split();
                string   animalName   = animalInfo[0];
                int      animalAge    = int.Parse(animalInfo[1]);
                string   animalGender = animalInfo[2];
                switch (type.ToLower())
                {
                case "cat":
                    Cat cat = new Cat(animalName, animalAge, animalGender);
                    Console.WriteLine(type);
                    Console.WriteLine(cat);
                    break;

                case "dog":
                    Dog dog = new Dog(animalName, animalAge, animalGender);
                    Console.WriteLine(type);
                    Console.WriteLine(dog);
                    break;

                case "frog":
                    Frog frog = new Frog(animalName, animalAge, animalGender);
                    Console.WriteLine(type);
                    Console.WriteLine(frog);
                    break;

                case "kitten":
                    Kitten kitten = new Kitten(animalName, animalAge);
                    Console.WriteLine(type);
                    Console.WriteLine(kitten);
                    break;

                case "tomcat":
                    Tomcat tomcat = new Tomcat(animalName, animalAge);
                    Console.WriteLine(type);
                    Console.WriteLine(tomcat);
                    break;

                default:
                    Animal animal = new Animal(animalName, animalAge, animalGender);
                    Console.WriteLine(type);
                    Console.WriteLine(animal);
                    break;
                }
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }

            type = Console.ReadLine();
        }
    }
 void OnMouseDown()
 {
     Kitten.Log("Mouse Down on ", buttonName);
     if (isTriggeredOnMouseDown && mouseDownAnimationName != null)
     {
         this.PlayAnimation(mouseDownAnimationName);
     }
 }
 void OnMouseExit()
 {
     Kitten.Log("Mouse Exit on ", buttonName);
     if (isTriggeredOnMouseExit && mouseExitAnimationName != null)
     {
         this.PlayAnimation(mouseExitAnimationName);
     }
 }
Exemplo n.º 17
0
    static void Main()
    {
        List <Animal> animals = new List <Animal>();
        string        command;

        while ((command = Console.ReadLine()) != "Beast!")
        {
            string   animalType = command;
            string[] input      = Console.ReadLine().Split().ToArray();

            string name   = input[0];
            int    age    = int.Parse(input[1]);
            string gender = input[2];
            try
            {
                switch (animalType.ToLower())
                {
                case "dog":
                    var dog = new Dog(name, age, gender);
                    animals.Add(dog);
                    break;

                case "frog":
                    var frog = new Frog(name, age, gender);
                    animals.Add(frog);
                    break;

                case "cat":
                    var cat = new Cat(name, age, gender);
                    animals.Add(cat);
                    break;

                case "kitten":
                    var kitten = new Kitten(name, age, gender);
                    animals.Add(kitten);
                    break;

                case "tomcat":
                    var tomcat = new Tomcat(name, age, gender);
                    animals.Add(tomcat);
                    break;

                default:
                    throw new ArgumentException("Invalid input!");
                }
            }


            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        foreach (var a in animals)
        {
            Console.WriteLine(a);
        }
    }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            try
            {
                Frog Goshko = new Frog("Goshko", 10, "male");
                Frog Dimitrur = new Frog("Dimitur",6, "male");
                Frog Minka = new Frog("Minka", 3, "female");

                Dog Rex = new Dog("Rex", 1, "male");
                Dog Hunter = new Dog("Hunter", 5, "male");
                Dog Blondie = new Dog("Blondie",3,"female");

                Kitten Puxy = new Kitten ("Puxy" , 2);
                Kitten Dazzy = new Kitten("Dazzy",5);
                Kitten Tuffy = new Kitten("Tuffy", 4);

                TomCat Tom = new TomCat("Tom", 4);
                TomCat Djeramaia = new TomCat("Djeramaia", 1);
                TomCat Virgin = new TomCat("Virgin",7);

                IList<Animal> animals = new List<Animal>
                {
                    Goshko,Dimitrur,Minka,Rex,Hunter,Blondie,Puxy,Dazzy,Tuffy,Tom,Djeramaia,Virgin
                };
                Goshko.ProduceSound();
                Rex.ProduceSound();
                Puxy.ProduceSound();
                Tom.ProduceSound();

                double catsAverageAge = animals
                    .Where(animal => animal is Cat)
                    .Average(cat => cat.Age);
                double dogsAverageAge = animals
                                    .Where(animal => animal is Dog)
                                    .Average(dog => dog.Age);

                double frogsAverageAge = animals
                    .Where(animal => animal is Frog)
                    .Average(frog => frog.Age);

                Console.WriteLine("Frogs average age is: {0:F2}", frogsAverageAge);
                Console.WriteLine("Dogs average age is: {0:F2}", dogsAverageAge);
                Console.WriteLine("Cats average age is: {0:F2}", catsAverageAge);

            }
            catch (ArgumentOutOfRangeException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentNullException ae)
            {
                Console.WriteLine(ae.Message);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }
        }
Exemplo n.º 19
0
    static void Main()
    {
        List <Animal> animals = new List <Animal>();
        string        animalType;

        while ((animalType = Console.ReadLine()) != "Beast!")
        {
            try
            {
                string[] animalInfo = Console.ReadLine().Split();
                string   name       = animalInfo[0];
                int      age        = int.Parse(animalInfo[1]);
                string   gender     = String.Empty;
                if (animalInfo.Length == 3)
                {
                    gender = animalInfo[2];
                }
                switch (animalType)
                {
                case "Cat":
                    Cat cat = new Cat(name, age, gender);
                    animals.Add(cat);
                    break;

                case "Dog":
                    Dog dog = new Dog(name, age, gender);
                    animals.Add(dog);
                    break;

                case "Frog":
                    Frog frog = new Frog(name, age, gender);
                    animals.Add(frog);
                    break;

                case "Kitten":
                    Kitten kitten = new Kitten(name, age);
                    animals.Add(kitten);
                    break;

                case "Tomcat":
                    Tomcat tomcat = new Tomcat(name, age);
                    animals.Add(tomcat);
                    break;

                default:
                    throw new ArgumentException("Invalid input!");
                }
            }
            catch (ArgumentException exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
        foreach (Animal animal in animals)
        {
            Console.WriteLine(animal);
        }
    }
Exemplo n.º 20
0
 public static Kitten[] FillKittenArr()
 {
     var kitArr = new Kitten[rnd.Next(5, 21)];
     for (int i = 0; i < kitArr.Length; i++)
     {
         kitArr[i] = new Kitten(GetRandomName(), rnd.Next(1, 16));
     }
     return kitArr;
 }
Exemplo n.º 21
0
    private static void ReadAnimals(List <Animal> animals, string command)
    {
        Animal animal     = new Animal();
        string animalType = "";

        for (int i = 0; i < 2; i++)
        {
            if (i == 1)
            {
                command = Console.ReadLine();
            }
            var input = command.Split(new[] { ' ' }, StringSplitOptions.None);
            if (input.Length == 1)
            {
                animalType = input[0];
            }
            else if (input.Length == 3)
            {
                var name   = input[0];
                var age    = int.Parse(input[1]);
                var gender = "";
                if (input.Length == 3)
                {
                    gender = input[2];
                }
                switch (animalType)
                {
                case "Cat":
                    animal = new Cat(name, age, gender);
                    break;

                case "Dog":
                    animal = new Dog(name, age, gender);
                    break;

                case "Frog":
                    animal = new Frog(name, age, gender);
                    break;

                case "Tomcat":
                    animal = new Tomcat(name, age);
                    break;

                case "Kitten":
                    animal = new Kitten(name, age);
                    break;

                default: throw new ArgumentException($"Invalid input!");
                }
                animals.Add(animal);
            }
            else
            {
                throw new ArgumentException($"Invalid input!");
            }
        }
    }
Exemplo n.º 22
0
        public void Run()
        {
            while (true)
            {
                var animalType = Console.ReadLine();

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

                try
                {
                    string[] animalArgs = Console.ReadLine().Split(" ");
                    string   name       = animalArgs[0];
                    int      age        = int.Parse(animalArgs[1]);
                    string   gender     = animalArgs[2];

                    switch (animalType)
                    {
                    case "Dog":
                        Dog dog = new Dog(name, age, gender);
                        this.animals.Add(dog);
                        break;

                    case "Cat":
                        Cat cat = new Cat(name, age, gender);
                        this.animals.Add(cat);
                        break;

                    case "Frog":
                        Frog frog = new Frog(name, age, gender);
                        this.animals.Add(frog);
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(name, age);
                        this.animals.Add(kitten);
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(name, age);
                        this.animals.Add(tomcat);
                        break;

                    default:
                        throw new InvalidInputException();
                    }
                }
                catch (InvalidInputException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            PrintAnimals();
        }
Exemplo n.º 23
0
        public static void Main()
        {
            Kitten kat = new Kitten("Sunny", 9);

            Console.WriteLine(kat);

            Tomcat grumpyCat = new Tomcat("Grumpy Cat", 5);

            Console.WriteLine(grumpyCat);

            kat.MakeSound();

            List <Dog> dogList = new List <Dog>()
            {
                new Dog("Rex", 6, Gender.Male),
                new Dog("Roxana", 4, Gender.Female),
                new Dog("Doge", 7, Gender.Male)
            };

            Console.WriteLine("\nAverage dog age: {0}\n", (int)dogList.Average(x => x.Age));

            List <Frog> forgList = new List <Frog>()
            {
                new Frog("Joro", 3, Gender.Female),
                new Frog("Queen Victoria", 2, Gender.Male),
                new Frog("Badass", 5, Gender.Male)
            };

            Console.WriteLine("Average frog age: {0}\n", (int)forgList.Average(x => x.Age));

            List <Cat> catList = new List <Cat>()
            {
                new Cat("Felicity", 11, Gender.Female),
                new Cat("Gesha", 4, Gender.Male),
                new Cat("Lorenzo", 2, Gender.Male)
            };

            Console.WriteLine("Average cat age: {0}\n", (int)catList.Average(x => x.Age));

            List <Kitten> kittenList = new List <Kitten>()
            {
                new Kitten("Shmatio", 6),
                new Kitten("Kitten", 2),
                kat
            };

            Console.WriteLine("Average kitten age: {0}\n", (int)kittenList.Average(x => x.Age));

            List <Tomcat> tomcatList = new List <Tomcat>()
            {
                new Tomcat("Gribbo", 13),
                new Tomcat("Batalen", 7),
                grumpyCat
            };

            Console.WriteLine("Average tomcat age: {0}\n", (int)tomcatList.Average(x => x.Age));
        }
Exemplo n.º 24
0
    static void Main(string[] args)
    {
        List <Animal> animals = new List <Animal>();

        string input;

        while ((input = Console.ReadLine()) != "Beast!")
        {
            try
            {
                var tokens = Console.ReadLine().Split();

                switch (input)
                {
                case "Cat":
                    Cat cat = new Cat(tokens[0], int.Parse(tokens[1]), tokens[2], "Cat");
                    animals.Add(cat);
                    break;

                case "Dog":
                    Dog dog = new Dog(tokens[0], int.Parse(tokens[1]), tokens[2], "Dog");
                    animals.Add(dog);
                    break;

                case "Frog":
                    Frog frog = new Frog(tokens[0], int.Parse(tokens[1]), tokens[2], "Frog");
                    animals.Add(frog);
                    break;

                case "Kitten":
                    Kitten kitten = new Kitten(tokens[0], int.Parse(tokens[1]), tokens[2], "Kitten");
                    animals.Add(kitten);
                    break;

                case "Tomcat":
                    Tomcat tomcat = new Tomcat(tokens[0], int.Parse(tokens[1]), tokens[2], "Tomcat");
                    animals.Add(tomcat);
                    break;

                default:
                    throw new ArgumentException("Invalid input!");
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        foreach (var animal in animals)
        {
            Console.WriteLine(animal.Type);
            Console.WriteLine($"{animal.Name} {animal.Age} {animal.Gender}");
            Console.WriteLine(animal.ProduceSound());
        }
    }
Exemplo n.º 25
0
    static void Main(string[] args)
    {
        var animals = new List <Animal>();

        string input;

        while ((input = Console.ReadLine()) != "Beast!")
        {
            string[] animalArg = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string   name      = animalArg[0];
            int      age       = int.Parse(animalArg[1]);
            string   gender    = animalArg[2];
            try
            {
                Animal animal;
                switch (input)
                {
                case "Dog":
                    animal = new Dog(name, age, gender);
                    animals.Add(animal);
                    break;

                case "Cat":
                    animal = new Cat(name, age, gender);
                    animals.Add(animal);
                    break;

                case "Frog":
                    animal = new Frog(name, age, gender);
                    animals.Add(animal);
                    break;

                case "Kitten":
                    animal = new Kitten(name, age, gender);
                    animals.Add(animal);
                    break;

                case "Tomcat":
                    animal = new Tomcat(name, age, gender);
                    animals.Add(animal);
                    break;

                default:
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Invalid input!");
            }
        }
        foreach (var item in animals)
        {
            Console.WriteLine(item);
        }
    }
Exemplo n.º 26
0
    public static void Main()
    {
        var animals = new List <Animal>();

        string kindOfAnimal;

        while ((kindOfAnimal = Console.ReadLine()) != "Beast!")
        {
            var animalTokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            try
            {
                switch (kindOfAnimal.ToLower().Trim())
                {
                case "cat":
                    Animal cat = new Cat(animalTokens[0], int.Parse(animalTokens[1]), animalTokens[2]);
                    animals.Add(cat);
                    break;

                case "dog":
                    Animal dog = new Dog(animalTokens[0], int.Parse(animalTokens[1]), animalTokens[2]);
                    animals.Add(dog);
                    break;

                case "frog":
                    Animal frog = new Frog(animalTokens[0], int.Parse(animalTokens[1]), animalTokens[2]);
                    animals.Add(frog);
                    break;

                case "kitten":
                    Animal kitten = new Kitten(animalTokens[0], int.Parse(animalTokens[1]), "Female");
                    animals.Add(kitten);
                    break;

                case "tomcat":
                    Animal tomcat = new Tomcat(animalTokens[0], int.Parse(animalTokens[1]), "Male");
                    animals.Add(tomcat);
                    break;

                default:
                    Console.WriteLine("Invalid input!");
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);;
            }
        }

        foreach (var an in animals)
        {
            Console.WriteLine(an.IntroduceAnimal());
            Console.WriteLine(an.ProduceSound());
        }
    }
Exemplo n.º 27
0
    public static void Main()
    {
        string animalName = Console.ReadLine();
        string line       = Console.ReadLine();

        while (animalName != "Beast!" && line != null)
        {
            string[] animalInfo = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var animal = new Animal();

            try
            {
                switch (animalName.ToLower())
                {
                case "cat":
                    animal = new Cat(animalInfo[0], animalInfo[1], animalInfo[2]);
                    Console.WriteLine(animalName);
                    Console.WriteLine(animal.ToString());
                    break;

                case "dog":
                    animal = new Dog(animalInfo[0], animalInfo[1], animalInfo[2]);
                    Console.WriteLine(animalName);
                    Console.WriteLine(animal.ToString());
                    break;

                case "frog":
                    animal = new Frog(animalInfo[0], animalInfo[1], animalInfo[2]);
                    Console.WriteLine(animalName);
                    Console.WriteLine(animal.ToString());
                    break;

                case "kitten":
                    animal = new Kitten(animalInfo[0], animalInfo[1], "Female");
                    Console.WriteLine(animalName);
                    Console.WriteLine(animal.ToString());
                    break;

                case "tomcat":
                    animal = new Tomcat(animalInfo[0], animalInfo[1], "Male");
                    Console.WriteLine(animalName);
                    Console.WriteLine(animal.ToString());
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            animalName = Console.ReadLine();
            line       = Console.ReadLine();
        }
    }
Exemplo n.º 28
0
    public static Kitten[] FillKittenArr()
    {
        var kitArr = new Kitten[rnd.Next(5, 21)];

        for (int i = 0; i < kitArr.Length; i++)
        {
            kitArr[i] = new Kitten(GetRandomName(), rnd.Next(1, 16));
        }
        return(kitArr);
    }
Exemplo n.º 29
0
    public static void Main()
    {
        string type = Console.ReadLine();

        while (type != "Beast!")
        {
            string[] animalArgs = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Animal   animal;

            try
            {
                string name   = animalArgs[0];
                string age    = animalArgs[1];
                string gender = string.Empty;

                switch (type)
                {
                case "Dog":
                    gender = animalArgs[2];
                    animal = new Dog(name, age, gender);
                    break;

                case "Cat":
                    gender = animalArgs[2];
                    animal = new Cat(name, age, gender);
                    break;

                case "Frog":
                    gender = animalArgs[2];
                    animal = new Frog(name, age, gender);
                    break;

                case "Kitten":
                    animal = new Kitten(name, age);
                    break;

                case "Tomcat":
                    animal = new Tomcat(name, age);
                    break;

                default:
                    animal = new Cat(null, null, null);
                    break;
                }

                PrintAnimal(animal);
            }
            catch (Exception)
            {
                Console.WriteLine("Invalid input!");
            }

            type = Console.ReadLine();
        }
    }
Exemplo n.º 30
0
    static void Main()
    {
        // Animal an00 = new Animal("animal", 99, Sex.Male); //- it is not possible to initialize Animal - the class is abstract

        Frog an01 = new Frog("Jabka", 1, Sex.Female);
        Console.Write("sound of a frog is:");
        an01.Makesound();
        Dog an02 = new Dog("Balkan", 5, Sex.Male);
        Console.Write("sound of a dog is:");
        an02.Makesound();
        Cat an03 = new Cat("Muro", 2, Sex.Male); // Cat could be male or female
        Cat an04 = new Cat("Izabela", 4, Sex.Female); // Cat could be male or female
        Console.Write("sound of a cat is:");
        an04.Makesound();
        Kitten an05 = new Kitten("Chochi", 2);  //Kitten is alwais female
        Console.WriteLine("Kitten's sex is {0}", an05.Sex);
        Console.Write("sound of a kitten is:");
        an05.Makesound();
           // an05.Sex = Sex.Male; //It is not possible to access/change the sex of an Animal
        Tomcat an06 = new Tomcat("Gosho", 5);
        Console.WriteLine("Tomcat's sex is {0}", an06.Sex);
        Console.Write("sound of a tomcat is:");
        an06.Makesound();

        Dog an07 = new Dog("Lara", 8, Sex.Female);
        Dog an08 = new Dog("Sharo", 3, Sex.Male);
        Frog an09 = new Frog("Cermit", 2, Sex.Male);
        Kitten an10 = new Kitten("Suzi", 5);
        Tomcat an11 = new Tomcat("Tom", 2);

        Frog[] frogs = { an01, an09 };
        Console.WriteLine("The average age of frogs is {0:f2}", Animal.AverageAge(frogs)); //Static method in class Animal
        Console.WriteLine("The average age of frogs calculated by lambda is {0:f2}",frogs.Average(x=>x.Age));

        Dog[] dogs = { an02, an07, an08};
        Console.WriteLine("The average age of dogs is {0:f2}", Animal.AverageAge(dogs));
        Console.WriteLine("The average age of dogs calculated by lambda is {0:f2}", dogs.Average(x => x.Age));

        Cat[] allKindOfCats = { an03, an04, an05, an06, an10, an11};
        Console.WriteLine("The average age of all kind of cats is {0:f2}", Animal.AverageAge(allKindOfCats));
        Console.WriteLine("The average age of all kin of cats calculated by lambda is {0:f2}", allKindOfCats.Average(x => x.Age));

        Console.WriteLine();
        //Mix array
        Animal[] allAnimals = { an01,an02,an03, an04,an05, an06, an07, an08, an09, an10, an11};
        //split mixed aray to groups
        var groups = from kind in allAnimals
                     group kind by kind.GetType() into species
                     select species;
        //calculate and print average age by groups
        foreach (var item in groups)
        {
            Console.WriteLine("Kind ->{0, -10}; Average age ->{1:f2}", item.Key.Name, item.Average(x => x.Age));
        }
    }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            try
            {
                List <Animal> animals = new List <Animal>();
                string        s1;
                do
                {
                    s1 = Console.ReadLine();
                    string[] s = Console.ReadLine().Split(' ');
                    switch (s1)
                    {
                    case "Cat":
                        if (s[2] == "Tomcats")
                        {
                            Tomcats tomcats = new Tomcats(s[0], int.Parse(s[1]), s[2]);
                            animals.Add(tomcats);
                        }
                        else if (s[2] == "Kitten")
                        {
                            Kitten kitten = new Kitten(s[0], int.Parse(s[1]), s[2]);
                            animals.Add(kitten);
                        }
                        else
                        {
                            Cat cat = new Cat(s[0], int.Parse(s[1]), s[2]);
                            animals.Add(cat);
                        }
                        break;

                    case "Dog":
                        Dog dog = new Dog(s[0], int.Parse(s[1]), s[2]);
                        animals.Add(dog);
                        break;

                    case "Frog":
                        Frog frog = new Frog(s[0], int.Parse(s[1]), s[2]);
                        animals.Add(frog);
                        break;
                    }
                } while (s1 != "Beast!");
                foreach (var i in animals)
                {
                    Type type = i.GetType();
                    Console.WriteLine(type);
                    Console.WriteLine(i);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey();
        }
    static void Main()
    {
        Dog[] dogs = new Dog[]
        {
            new Dog(5, "Sharo", 'm'),
            new Dog(8, "Johnny", 'm'),
            new Dog(2, "Brian", 'm')
        };

        Frog[] frogs = new Frog[]
        {
            new Frog(1, "Kikirica", 'f'),
            new Frog(2, "Jaborana", 'f')
        };

        Cat[] cats = new Cat[]
        {
            new Cat(5, "Pisana", 'f'),
            new Cat(3, "Stefka", 'f'),
            new Cat(7, "Roshko", 'm'),
            new Cat(4, "Maca", 'f')
        };

        Kitten[] kittens = new Kitten[]
        {
            new Kitten(1, "Pisana"),
            new Kitten(1, "Belosnejka"),
            new Kitten(1, "Cecka")
        };

        Tomcat[] tomcats = new Tomcat[]
        {
            new Tomcat(14, "Tom"),
            new Tomcat(7, "Rich"),
            new Tomcat(3, "Roshko 2")
        };

        Console.WriteLine("Average age of Dogs: {0}", AverageAge(dogs));
        Console.WriteLine("Average age of Frogs: {0}", AverageAge(frogs));
        Console.WriteLine("Average age of Cats: {0}", AverageAge(cats));
        Console.WriteLine("Average age of Kittens: {0}", AverageAge(kittens));
        Console.WriteLine("Average age of Tomcats: {0}", AverageAge(tomcats));

        Console.WriteLine("Sounds:");
        Console.Write("\tThe dog says: ");
        dogs[0].MakeSound();
        Console.Write("\tThe frog says: ");
        frogs[0].MakeSound();
        Console.Write("\tThe cat says: ");
        cats[0].MakeSound();
        Console.Write("\tThe kitten says: ");
        kittens[0].MakeSound();
        Console.Write("\tThe tomcat says: ");
        tomcats[0].MakeSound();
    }
        public static void Main(string[] args)
        {
            var kitten = new Kitten()
            {
                Name = "Mr Fluffykins", FurColour = "Brown", Number = 12
            };

            var anonymousKitten = Nullify(kitten, c => c.Name, c => c.Number);

            Console.Read();
        }
Exemplo n.º 34
0
        private bool KittenIsUnique(Kitten kitten)
        {
            var existingKittenWithSameName = _context.Kittens.Any(x => x.Name == kitten.Name);

            if (existingKittenWithSameName)
            {
                ModelState.AddModelError("NON_UNIQUE_KITTEN", "Geef je kittens aub unieke namen, ze lijken al zo hard op elkaar.");
                return(false);
            }
            return(true);
        }
Exemplo n.º 35
0
        public void AddKitten(KittenViewModel model)
        {
            var kitten = new Kitten
            {
                Name  = model.Name,
                Age   = model.Age,
                Breed = (Breed)Enum.Parse(typeof(Breed), model.Breed, true)
            };

            this.context.Kittens.Add(kitten);
            this.context.SaveChanges();
        }
 void SpawnCat(Vector3 pos, Vector3 vel)
 {
     if (numCats == data.Length)
     {
         Array.Resize <Kitten>(ref data, 2 * data.Length);
     }
     data[numCats++] = new Kitten()
     {
         pos = pos, vel = vel
     };
     dataChanged = true;
 }
Exemplo n.º 37
0
        public void AddKitten(string name, int age, string breed)
        {
            var kitten = new Kitten
            {
                Name  = name,
                Breed = Enum.Parse <Breed>(breed),
                Age   = age
            };

            this.db.Kittens.Add(kitten);
            this.db.SaveChanges();
        }
Exemplo n.º 38
0
        public IActionResult Update(Kitten kitten, int id)
        {
            var kittenToUpdate = dbContext.Kittens.FirstOrDefault(c => c.ID == id);

            kittenToUpdate.Name       = kitten.Name;
            kittenToUpdate.Age        = kitten.Age;
            kittenToUpdate.PictureURL = kitten.PictureURL;
            kittenToUpdate.Size       = kitten.Size;
            kittenToUpdate.Color      = kitten.Color;
            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 39
0
        static void Main()
        {
            Animal[] dogArray = new Animal[5];
            dogArray[0] = new Dog("Sharo", 4, "male");
            dogArray[1] = new Dog("Rex", 1, "male");
            dogArray[2] = new Dog("Lasi", 10, "male");
            dogArray[3] = new Dog("Djinka", 3, "female");
            dogArray[4] = new Dog("Princess", 2, "female");

            foreach (var animal in dogArray)
            {
                Console.WriteLine(animal);
            }

            var dogArrayAvg = dogArray.Average(d => d.Age);
            Console.WriteLine("Average dog age: {0:F2}{1}",dogArrayAvg, Environment.NewLine);
            Console.WriteLine();


            Cat[] catArray = new Cat[5];
            catArray[0] = new Kitten("Mici", 3);
            catArray[1] = new Tomcat("Tom", 5);
            catArray[2] = new Kitten("Grozdanka", 2);
            catArray[3] = new Tomcat("Grozdan", 10);
            catArray[4] = new Kitten("Micana", 7);

            foreach (var cat in catArray)
            {
                Console.WriteLine(cat);
            }

            var catArrayAvg = catArray.Average(c => c.Age);
            Console.WriteLine("Average cat age: {0:F2}{1}",catArrayAvg, Environment.NewLine);
            Console.WriteLine();


            Frog[] frogArray = new Frog[5];
            frogArray[0] = new Frog("Kyrmit", 4, "male");
            frogArray[1] = new Frog("Kyrmita", 2, "female");
            frogArray[2] = new Frog("Kyrmin", 6, "male");
            frogArray[3] = new Frog("Kyrmina", 3, "female");
            frogArray[4] = new Frog("Kyrtin", 8, "male");

            foreach (var frog in frogArray)
            {
                Console.WriteLine(frog);
            }

            var frogArrayAvg = frogArray.Average(f => f.Age);
            Console.WriteLine("Average frog age: {0:F2}{1}", frogArrayAvg, Environment.NewLine);
            Console.WriteLine();
        }
Exemplo n.º 40
0
    static void Main(string[] args)
    {
        string type;

        while (!(type = Console.ReadLine()).Equals("Beast!"))
        {
            var tokens = Console.ReadLine()
                         .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            try
            {
                if (tokens.Length != 3)
                {
                    throw new ArgumentException("Invalid input!");
                }

                Animal animal = null;
                switch (type)
                {
                case "Cat":
                    animal = new Cat(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    break;
                    ;

                case "Dog":
                    animal = new Dog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    break;

                case "Frog":
                    animal = new Frog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    break;
                    ;

                case "Kitten":
                    animal = new Kitten(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    break;

                case "Tomcat":
                    animal = new Tomcat(tokens[0], int.Parse(tokens[1]), tokens[2]);
                    break;

                default:
                    throw new ArgumentException("Invalid input!");
                }
                Console.WriteLine(animal);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
Exemplo n.º 41
0
        public void Setup()
        {
            var firstKitten = new Kitten {
                Id = 1, Name = "Kitten"
            };

            cat = new Cat
            {
                Id          = 100,
                Name        = "Cat",
                FirstKitten = firstKitten,
                Picture     = new Bitmap(5, 5),
                AllKittens  = new List <Kitten>
                {
                    firstKitten,
                    new Kitten {
                        Id = 2, Name = "Kitten2"
                    },
                }
            };

            firstKitten = new Kitten {
                Id = 1, Name = "IdenticalKitten"
            };
            identicalCat = new Cat
            {
                Id          = 100,
                Name        = "IdenticalCat",
                FirstKitten = firstKitten,
                Picture     = new Bitmap(5, 5),
                AllKittens  = new List <Kitten>
                {
                    firstKitten,
                    new Kitten {
                        Id = 2, Name = "IdenticalKitten2"
                    },
                }
            };

            transaction = MockRepository.GenerateStub <ITransaction>();

            session = MockRepository.GenerateStub <ISession>();
            session.Stub(s => s.BeginTransaction()).Return(transaction);
            session.Stub(s => s.Get <Cat>(null)).IgnoreArguments().Return(identicalCat);
            session.Stub(s => s.GetIdentifier(cat)).Return(cat.Id);

            sessionSource = MockRepository.GenerateStub <ISessionSource>();
            sessionSource.Stub(ss => ss.CreateSession()).Return(session);

            spec = new PersistenceSpecification <Cat>(sessionSource, new TestComparer());
        }
    static void Main()
    {
        Cat[] cats = new Cat[5];
        cats[0] = new Tomcat("Murry", 2);
        cats[1] = new Kitten("Glori", 4, "January");
        cats[2] = new Tomcat("Ico", 3, "Orange", "Mice");
        cats[3] = new Kitten("Katya", 2, "March");
        cats[4] = new Tomcat("Tom", 5);

        Console.WriteLine("The average age of the cats is: " + cats.Average(c => c.Age));

        Dog doggy = new Dog("Persin", 6, "Male", "English Pointer");
        doggy.ProduceSound();
    }
Exemplo n.º 43
0
        static void Main()
        {
            Kitten violeta = new Kitten("Violeta", 24, 'F');
            violeta.ProduceSound();
            Cat violetka = new Cat("Vili", 24, 'F');
            violetka.ProduceSound();
            Dog ivan = new Dog("Ivan", 23, 'M');
            ivan.ProduceSound();

            List<Animal> animals = new List<Animal>
            {
                new Dog("Ivan", 2, 'M'),
                new Dog("Rex", 5, 'M'),
                new Dog("Laiza", 1, 'F'),
                new Frog("Jaba", 3, 'F'),
                new Frog("Chervena jaba", 15, 'M'),
                new Frog("Kiorava jaba", 7, 'F'),
                new Cat("Sivushka", 4 , 'F'),
                new Cat("Felix", 8, 'M'),
                new Tomcats("Gosho", 2, 'M'),
                new Kitten("Kitty", 1, 'F')
            };

            var cats =
                from animal in animals
                where animal is Cat
                select animal;

            Console.WriteLine("Average cats age is: {0:F2}", ((double)cats.Sum(c => c.Age) / cats.Count()));

            var dogs =
                from animal in animals
                where animal is Dog
                select animal;

            Console.WriteLine("Average dogs age is: {0:F2}", ((double)dogs.Sum(d => d.Age) / dogs.Count()));

            var frogs =
                from animal in animals
                where animal is Frog
                select animal;

            Console.WriteLine("Average cats age is: {0:F2}", ((double)frogs.Sum(f => f.Age) / frogs.Count()));
            Console.WriteLine();

            foreach (var animal in animals)
            {
                animal.ProduceSound();
            }
        }
Exemplo n.º 44
0
        public static void CheckSexAnimal()
        {
            try
            {
                Kitten myPet = new Kitten("Jessica", 3, Sex.male);
            }
            catch (ArgumentException ex)
            {

                Console.WriteLine(ex.Message);
                return;
            }
            // So it works ....
        }
    // generates random animals
    public static Animal GetRandomAnimal()
    {
        seed = rnd.Next(1, 5);

        switch (seed)
        {
            case 1:
                Sex s = sexes[rnd.Next(0, sexes.Length)]; // get random sex for the animal
                // give the animal a name corresponding to its sex
                string name = s == Sex.Male ? names[rnd.Next(0, names.Length)] : femNames[rnd.Next(0, femNames.Length)];
                // create new animal
                var doge = new Dog(name, s, (uint)rnd.Next(0, maxAge));
                // add his years in the years array
                animalsCountAndAges[0] += doge.Age;
                animalsCountAndAges[1]++;
                // return the new animal
                return doge;

            case 2:
                Sex frogS = sexes[rnd.Next(0, sexes.Length)];
                string frogName = frogS == Sex.Male ? names[rnd.Next(0, names.Length)] : femNames[rnd.Next(0, femNames.Length)];

                var froge = new Frog(frogName, frogS, (uint)rnd.Next(0, maxAge));

                animalsCountAndAges[2] += froge.Age;
                animalsCountAndAges[3]++;

                return froge;

            case 3:
                var kitty = new Kitten(femNames[rnd.Next(0, femNames.Length)], (uint)rnd.Next(0, maxAge));

                animalsCountAndAges[4] += kitty.Age;
                animalsCountAndAges[5]++;

                return kitty;

            case 4:
                var tommy = new Tomcat(names[rnd.Next(0, names.Length)], (uint)rnd.Next(0, maxAge));

                animalsCountAndAges[6] += tommy.Age;
                animalsCountAndAges[7]++;

                return tommy;

            default: throw new ArgumentException("Invalid seed");
        }
    }
Exemplo n.º 46
0
        static void Main(string[] args)
        {
            _animalsArr = new Animal[5];

            _animalsArr[0] = new Frog("Froggy", 3, 'm');
            _animalsArr[1] = new Dog("Kudgo", 10, 'm');
            _animalsArr[2] = new Kitten("Pussy", 3);
            _animalsArr[3] = new Tomcat("Kotaran", 4);
            _animalsArr[4] = new Dog("Big Bertha", 11, 'f');

            foreach (var a in _animalsArr.GroupBy(x => x.GetType().Name))
            {
                Console.WriteLine("Animal: {0}\nAvarage Age: {1}\n",
                    a.Key, a.Select(x => x.Age).Average());
            }
        }
Exemplo n.º 47
0
    static void Main()
    {
        Dog[] dogArray = new Dog[10];
        for (int i = 0; i < 10; i++)
        {
            dogArray[i] = new Dog(0, "Rover", "Male");
            dogArray[i].SetRandomAge(0, 15);
        }
        Console.WriteLine("Average years of the Dog array: " + Animal.AverageAge(dogArray));
        Console.WriteLine();

        Frog[] frogArray = new Frog[10];
        for (int i = 0; i < 10; i++)
        {
            frogArray[i] = new Frog(0, "Wib", "Male");
            frogArray[i].SetRandomAge(0, 20);
        }
        Console.WriteLine("Average years of the Frog array: " + Animal.AverageAge(frogArray));
        Console.WriteLine();

        Cat[] catArray = new Cat[10];
        for (int i = 0; i < 10; i++)
        {
            catArray[i] = new Cat(0, "Whiskers", "Male");
            catArray[i].SetRandomAge(0, 22);
        }
        Console.WriteLine("Average years of the Cat array: " + Animal.AverageAge(catArray));
        Console.WriteLine();

        Tomcat[] tomcatArray = new Tomcat[10];
        for (int i = 0; i < 10; i++)
        {
            tomcatArray[i] = new Tomcat(0, "Tom");
            tomcatArray[i].SetRandomAge(0, 22);
        }
        Console.WriteLine("Average years of the Tomcat array: " + Animal.AverageAge(tomcatArray));
        Console.WriteLine();

        Kitten[] kittenArray = new Kitten[10];
        for (int i = 0; i < 10; i++)
        {
            kittenArray[i] = new Kitten(0, "Felicity");
            kittenArray[i].SetRandomAge(0, 22);
        }
        Console.WriteLine("Average years of the Kitten array: " + Animal.AverageAge(kittenArray));
        Console.WriteLine();
    }
Exemplo n.º 48
0
        static void Main(string[] args)
        {
            Cat[] cats = new Cat[]
            {
                new Cat("Aira", 2, Sex.female),
                new Cat("Roni", 6, Sex.male),
                new Cat("Ketty", 3, Sex.female),
            };

            Console.WriteLine(Animal.AverageAge(cats));

            Dog[] dogs = new Dog[]
            {
                new Dog("Rijko", 4, Sex.male),
                new Dog("Roni", 5, Sex.male),
                new Dog("Molly", 3, Sex.female),
            };

            Console.WriteLine(Animal.AverageAge(dogs));

            Kitten[] kittens = new Kitten[]
            {
                new Kitten("Kremi", 3),
                new Kitten("Maca", 1),
                new Kitten("Murja", 8),
            };

            Console.WriteLine(Animal.AverageAge(kittens));

            Tomcat[] tomcats = new Tomcat[]
            {
                new Tomcat("Rijka", 2),
                new Tomcat("Bojka", 1),
                new Tomcat("Sara", 10),
            };

            Console.WriteLine(Animal.AverageAge(tomcats));

            Frog[] frogs = new Frog[]
            {
                new Frog("Ash", 1, Sex.female),
                new Frog("Hrk", 1, Sex.female),
                new Frog("JKl", 1, Sex.female),
            };

            Console.WriteLine(Animal.AverageAge(frogs));
        }
Exemplo n.º 49
0
        static void Main(string[] args)
        {
            Dog firstDog = new Dog(2, "Sharo");
            Dog secondDog = new Dog(6, "Djaro");
            Dog thirdDog = new Dog(1, "Tobi");
            Dog fourthDog = new Dog(5, "Roni");

            Dog[] dogs = new Dog[]
            {
                firstDog, secondDog, thirdDog, fourthDog
            };

            Console.WriteLine("The average age of the dogs is: {0}", Animal.GetAverageAge(dogs));
            firstDog.MakeSound();
            Console.WriteLine();

            Cat firstCat = new Kitten(1, "Kitty");
            Cat secondCat = new Tomcat(2, "Bojko");
            Cat thirdCat = new Cat(4, "Myrzel", "male");

            Cat[] cats = new Cat[] 
            {
                firstCat,
                secondCat,
                thirdCat
            };

            Console.WriteLine("The average age of the cats is: {0}", Animal.GetAverageAge(cats));
            Console.WriteLine();
            
            Console.WriteLine("The kitten's name is: {0} ", firstCat.GetName());
            Console.WriteLine("The kitten's age is: {0}", firstCat.GetAge());
            Console.WriteLine("All kittens are {0}", firstCat.Sex);
            firstCat.MakeSound();
            Console.WriteLine();

            Console.WriteLine("The tomcat's name is: {0}", secondCat.GetName());
            Console.WriteLine("All tomcats are {0}", secondCat.Sex);
            secondCat.MakeSound();

            thirdCat.MakeSound();
            Console.WriteLine();

            Frog froggy = new Frog(22, "Prince");
            froggy.MakeSound();

        }
        static void Main()
        {
            Frog f1 = new Frog("Billy", 0.2, "m");
            Dog d1 = new Dog("Liza", 4, "f");
            Cat c1 = new Cat("Kotaksi", 2, "m");
            Kitten k1 = new Kitten("Raya", 1);
            Tomcat t1 = new Tomcat("Rijo", 2);

            f1.ProduceSound();
            d1.ProduceSound();
            c1.ProduceSound();
            k1.ProduceSound();
            t1.ProduceSound();

            Console.WriteLine();

            Animal[] animals = new Animal[]
            {
                new Frog("Billy", 0.2, "m"),
                new Dog("Liza", 4, "f"),
                new Cat("Kotaksi", 2, "m"),
                new Kitten("Raya", 1),
                new Tomcat("Rijo", 2),
                new Frog("Pesho", 2.1, "f"),
                new Dog("Beti", 5.4, "f"),
                new Cat("Kotka", 2, "f"),
                new Kitten("Spaska", 4),
                new Tomcat("Gosho", 3),
                new Frog("Marmot", 4, "m"),
                new Tomcat("Bizen", 0.5),
                new Dog("India", 2.5, "f"),
            };

            animals.
                GroupBy(animal => animal.GetType().Name).
                Select(group => new
                {
                    name = group.Key,
                    averageYears = group.Average(animal => animal.Age)
                }).
                ToList().
                ForEach(group => Console.WriteLine("Group: {0}, average age: {1:F2} years!", group.name, group.averageYears));
        }
        public void Setup()
        {
            var firstKitten = new Kitten { Id = 1, Name = "Kitten" };
            cat = new Cat
            {
                Id = 100,
                Name = "Cat",
                FirstKitten = firstKitten,
                Picture = new Bitmap(5, 5),
                AllKittens = new List<Kitten>
                {
                    firstKitten,
                    new Kitten {Id = 2, Name = "Kitten2"},
                }
            };

            firstKitten = new Kitten { Id = 1, Name = "IdenticalKitten" };
            identicalCat = new Cat
            {
                Id = 100,
                Name = "IdenticalCat",
                FirstKitten = firstKitten,
                Picture = new Bitmap(5, 5),
                AllKittens = new List<Kitten>
                {
                    firstKitten,
                    new Kitten {Id = 2, Name = "IdenticalKitten2"},
                }
            };

            transaction = A.Fake<ITransaction>();

            session = A.Fake<ISession>();
            A.CallTo(() => session.BeginTransaction()).Returns(transaction);
            A.CallTo(() => session.Get<Cat>(null)).WithAnyArguments().Returns(identicalCat);
            A.CallTo(() => session.GetIdentifier(cat)).Returns(cat.Id);

            sessionSource = A.Fake<ISessionSource>();
            A.CallTo(() => sessionSource.CreateSession()).Returns(session);

            spec = new PersistenceSpecification<Cat>(sessionSource, new TestComparer());
        }
        public void Setup()
        {
            var firstKitten = new Kitten { Id = 1, Name = "Kitten" };
            _cat = new Cat
            {
                Id = 100,
                Name = "Cat",
                FirstKitten = firstKitten,
                Picture = new Bitmap(5, 5),
                AllKittens = new List<Kitten>
                {
                    firstKitten,
                    new Kitten {Id = 2, Name = "Kitten2"},
                }
            };

            firstKitten = new Kitten { Id = 1, Name = "IdenticalKitten" };
            _identicalCat = new Cat
            {
                Id = 100,
                Name = "IdenticalCat",
                FirstKitten = firstKitten,
                Picture = new Bitmap(5, 5),
                AllKittens = new List<Kitten>
                {
                    firstKitten,
                    new Kitten {Id = 2, Name = "IdenticalKitten2"},
                }
            };

            _transaction = MockRepository.GenerateStub<ITransaction>();

            _session = MockRepository.GenerateStub<ISession>();
            _session.Stub(s => s.BeginTransaction()).Return(_transaction);
            _session.Stub(s => s.Get<Cat>(null)).IgnoreArguments().Return(_identicalCat);
            _session.Stub(s => s.GetIdentifier(_cat)).Return(_cat.Id);

            _sessionSource = MockRepository.GenerateStub<ISessionSource>();
            _sessionSource.Stub(ss => ss.CreateSession()).Return(_session);

            _spec = new PersistenceSpecification<Cat>(_sessionSource, new TestComparer());
        }
        public static void Main()
        {
            var kittenTea = new Kitten("Tea", 2);
            var tomcatRoko = new Tomcat("Roko", 4);
            var kittenCeca = new Kitten("Ceca", 1);

            var dogBalkan = new Dog("Balkan", 3, Gender.Male);
            var dogSara = new Dog("Sara", 2, Gender.Female);

            var frogKermit = new Frog("Kermit", 1, Gender.Male);
            var frogCarlotta = new Frog("Carlotta", 2, Gender.Female);

            var animals = new Animal[] { kittenTea, tomcatRoko, kittenCeca, dogBalkan, dogSara, frogKermit, frogCarlotta };

            Animal.PrintAverageAge(animals);

            foreach (var animal in animals)
            {
                animal.ProduceSound();
            }
        }
Exemplo n.º 54
0
    static void Main()
    {
        Dog[] dogs = new Dog[]
        {
            new Dog("Sharo", 5, Gender.Male),
            new Dog("Rex", 8, Gender.Male)
        };

        Frog[] frogs = new Frog[]
        {
            new Frog("Grogo", 1, Gender.Male),
            new Frog("Frogina", 3, Gender.Female)
        };

        Kitten[] kittens = new Kitten[]
        {
            new Kitten("Fluffy", 5),
            new Kitten("Patrisha", 2)
        };

        Tomcat[] tomcats = new Tomcat[]
        {
            new Tomcat("Tom", 3),
            new Tomcat("Johnny", 5)
        };

        List<Animal[]> animals = new List<Animal[]>();
        animals.Add(dogs);
        animals.Add(frogs);
        animals.Add(kittens);
        animals.Add(tomcats);

        Console.WriteLine("Average age by animal type:");
        foreach (var animalArray in animals)
        {
            Console.WriteLine("{0}:\t{1};",
                animalArray[0].GetType(), //assumes non-empty arrays
                GetAverageAge(animalArray));
        }
    }
Exemplo n.º 55
0
    static void Main()
    {
        Animal[] animalsList =
        {
            new Dog("Rex", 7, Sex.Female),
            new Cat("Dogfood", 2, Sex.Female),
            new Cat("Bloodhound", 6, Sex.Male),
            new Tomcat("Kitty", 102),
            new Tomcat("Kitty Junior", 3)        
        };
        //average age
        var animalGroups =
                from animal in animalsList
                group animal by animal.GetType().Name into groups
                select new
                {
                    Name = groups.Key,
                    AverageAge =
                        (from anim in groups
                         select anim.Age).Average()
                };

        //print average age
        foreach (var group in animalGroups)
        {
            Console.WriteLine("{0} average age: {1}", group.Name, group.AverageAge);
        }
        Console.WriteLine("\nSome tests");
        //Kitten
        Kitten kitkat = new Kitten("Kitkat", 6);
        Console.WriteLine("The kitten says:");
        kitkat.Talk();
        Console.WriteLine("{0} is {1}", kitkat.Name, kitkat.Sex);
        //Frog
        Frog princess = new Frog("Princess", 21, Sex.Female);
        Console.WriteLine("The frog says:");
        princess.Talk();
    }
Exemplo n.º 56
0
        static void Main(string[] args)
        {
            Dog myDog = new Dog("Sharo", 2, "male");
            myDog.MakeSound();

            Cat kitten = new Kitten("Lola", 4);
            Console.WriteLine(kitten.Sex);
            kitten.MakeSound();                        //Different sound results for the two cats, because one is initiated as a Cat and the other as a Kitten

            Kitten secondKitten = new Kitten("Muhla", 1);
            secondKitten.MakeSound();

            List<Animal> animalList = new List<Animal>();
            animalList.Add(new Dog("Burkan", 5, "male"));
            animalList.Add(new Dog("Penka", 2, "female"));
            animalList.Add(new Kitten("Karma", 1));
            animalList.Add(new Kitten("Shusha", 3));
            animalList.Add(new Tomcat("Roshko", 6));
            animalList.Add(new Frog("Galoshko", 1, "male"));
            animalList.Add(new Frog("Zelen", 2, "male"));

            var animalsByKind =
                (from animal in animalList
                 group animal by animal.GetType().Name into newGroup
                 select new
                 {
                     animalKind = newGroup.Key,
                     averageAge =
                          (from sortedAnimals in newGroup
                           select sortedAnimals.Age).Average()
                 });

            Console.WriteLine("Animal kinds with average age:");
            foreach (var group in animalsByKind)
            {
                Console.WriteLine(group);
            }
        }
Exemplo n.º 57
0
    static void Main()
    {
        var tom = new Tomcat("Tommas", 3, "m");
        var bruno = new Tomcat("Bruno", 1, "male");
        var spike = new Dog("Spike", 4, "m");
        var dog = new Dog("Бенджи", 4, "male");
        var frog =  new Frog("Veso", 1, "female");
        var anotherFrog = new Frog("Sasho", 2, "m");
        var kitten = new Kitten("Kote", 2, "female");
        var cat = new Cat("Маца", 5, "f");
        var anotherKitty = new Kitten("Penka", 4, "female");

        Animal[] animals = new Animal[]
           {
           tom, dog, frog, kitten, cat, spike, bruno, anotherFrog, anotherKitty
           };

        foreach (var kind in animals.GroupBy(animal => animal.GetType()))
        {
            double averageAge = kind.Average(animal => (double)animal.Age);
            Console.WriteLine("{0} - average age: {1}", kind.Key, averageAge);
        }
    }
Exemplo n.º 58
0
    static void Main(string[] args)
    {
        Dog dog = new Dog("Rex", 4, AnimalSex.Male);
        Console.WriteLine(dog.MakeSound());

        Kitten kitten = new Kitten("Kitty", 1);
        Console.WriteLine(kitten.MakeSound());

        List<Animal> animals = new List<Animal>() { dog, kitten };

        animals.Add(new Dog("Alice", 3, AnimalSex.Female));
        animals.Add(new Frog("Terminator", 5, AnimalSex.Male));
        animals.Add(new Tomcat("Tom", 2));

        Console.WriteLine("\n{0}\n", new string('-', 25));

        var getAllKindsOfAnimals = animals.GroupBy(x => x.GetType()); // grouping animals by type( classes )

        foreach (var type in getAllKindsOfAnimals)
        {
            Console.WriteLine("{0}s: Average age = {1}", type.Key.Name, type.Average(x => x.Age));
        }
    }
 public void AddKitten(Kitten kitten)
 {
     AllKittens.Add(kitten);
 }
Exemplo n.º 60
0
    static void Main()
    {
        // Produce sounds
        Kitten kitty = new Kitten("Pepa", 1);
        kitty.ProduceSound();

        Frog kyrmit = new Frog("Kyrmit", 3, Sex.Male);
        kyrmit.ProduceSound();

        Tomcat tom = new Tomcat("Tom", 8);
        tom.ProduceSound();

        Dog sharo = new Dog("Sharo", 15, Sex.Male);
        sharo.ProduceSound();

        Console.WriteLine();

        // Initializing list of Animals
        List<Animal> tomcats = new List<Animal>()
        {
            // Sex is always male
            new Tomcat("Tom", 8),
            new Tomcat("Bill", 9),
            new Tomcat("John", 7),
            new Tomcat("Gogo", 10),
            new Tomcat("Thomas", 11)
        };

        List<Animal> kittens = new List<Animal>()
        {
            // Sex is always female
            new Kitten("Kitty", 1),
            new Kitten("Kit", 2),
            new Kitten("Jitty", 1),
            new Kitten("Mitty", 1),
            new Kitten("Gitty", 2)
        };


        List<Animal> frogs = new List<Animal>()
        {
            new Frog("Kyrmit", 3, Sex.Male),
            new Frog("Maria", 2, Sex.Female),
            new Frog("Grigor", 3, Sex.Male),
            new Frog("Mara", 2, Sex.Female),
            new Frog("Mimi", 3, Sex.Female)
        };

        List<Animal> dogs = new List<Animal>()
        {
            new Dog("Sharo", 12, Sex.Male),
            new Dog("Billy", 14, Sex.Male),
            new Dog("Doggy", 11, Sex.Male),
            new Dog("Milka", 10, Sex.Female),
            new Dog("Mimi", 12, Sex.Female)
        };  

        // Calculating average age of animals
        double average = AverageAgeCalculator.CalculateAverageAge(tomcats);
        Console.WriteLine("Average Tomcat age is: {0}", average);

        average = AverageAgeCalculator.CalculateAverageAge(kittens);
        Console.WriteLine("Average Kitten age is: {0}", average);

        average = AverageAgeCalculator.CalculateAverageAge(frogs);
        Console.WriteLine("Average Frog age is: {0}", average);

        average = AverageAgeCalculator.CalculateAverageAge(dogs);
        Console.WriteLine("Average Dog age is: {0}", average);
    }