Beispiel #1
0
    static void Main(string[] args)
    {
        Console.WriteLine("Exercise 1");
        var dog = new Dog();

        dog.Eat();
        dog.Bark();
        Console.WriteLine();

        Console.WriteLine("Exercise 2");
        var puppy = new Puppy();

        puppy.Eat();
        puppy.Bark();
        puppy.Weep();
        Console.WriteLine();

        Console.WriteLine("Exercise 3");
        dog.Eat();
        dog.Bark();
        var cat = new Cat();

        cat.Eat();
        cat.Meow();
    }
        public static void Main()
        {
            var puppy = new Puppy();

            puppy.Eat();
            puppy.Bark();
            puppy.Weep();
        }
Beispiel #3
0
    static void Main(string[] args)
    {
        var dog = new Puppy();

        dog.Eat();
        dog.Bark();
        dog.Weep();
    }
Beispiel #4
0
    static void Main()
    {
        Puppy puppy = new Puppy();

        puppy.Eat();
        puppy.Bark();
        puppy.Weep();
    }
Beispiel #5
0
    static void Main(string[] args)
    {
        Puppy puppy = new Puppy();

        puppy.Eat();
        puppy.Bark();
        puppy.Weep();
    }
        static void Main(string[] args)
        {
            Puppy littleOne = new Puppy();

            littleOne.Bark();
            littleOne.Eat();
            littleOne.Wheep();
        }
Beispiel #7
0
    static void Main(string[] args)
    {
        Puppy sweety = new Puppy();

        sweety.Weep();
        sweety.Bark();
        sweety.Eat();
    }
Beispiel #8
0
        public static void PuppyPower()
        {
            Puppy theCutest = new Puppy();

            Console.WriteLine(theCutest.Have());
            Console.WriteLine(theCutest.HaveVocalChords());
            Console.WriteLine(theCutest.Eat());
            Console.WriteLine(theCutest.Chew());
            Console.WriteLine(theCutest.Are());
        }
    public static void Main(string[] args)
    {
        Puppy dog = new Puppy();

        dog.Eat();
        dog.Bark();

        Cat cat = new Cat();

        cat.Eat();
        cat.Meow();
    }
        public static void Main()
        {
            Dog dog = new Dog();

            dog.Bark();
            dog.Eat();

            Puppy puppy = new Puppy();

            puppy.Weep();
            puppy.Bark();
            puppy.Eat();
        }
Beispiel #11
0
        public static void Main()
        {
            var puppy = new Puppy();

            puppy.Eat();
            puppy.Bark();
            puppy.Weep();

            var cat = new Cat();

            cat.Eat();
            cat.Meow();
        }
Beispiel #12
0
        static void Main()
        {
            var dog = new Dog();

            dog.Eat();
            dog.Bark();

            var puppy = new Puppy();

            puppy.Eat();
            puppy.Bark();
            puppy.Weep();
        }
Beispiel #13
0
        static void Main()
        {
            Animal animal = new Animal();
            Dog    dog    = new Dog();
            Puppy  puppy  = new Puppy();
            Cat    cat    = new Cat();

            animal.Eat();
            dog.Eat();
            dog.Bark();
            puppy.Eat();
            puppy.Bark();
            puppy.Weep();
            cat.Eat();
            cat.Meow();
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            Puppy puppy = new Puppy();

            puppy.Bark();
            puppy.Eat();
            puppy.Weep();

            Animal animal = new Animal();

            animal.Eat();

            Dog dog = new Dog();

            dog.Bark();
            dog.Eat();
        }
Beispiel #15
0
    static void Main(string[] args)
    {
        Dog dog = new Dog();

        dog.Eat();
        dog.Bark();

        Puppy puppy = new Puppy();

        puppy.Eat();
        puppy.Bark();
        puppy.Weep();

        Cat cat = new Cat();

        cat.Eat();
        cat.Meow();
    }
Beispiel #16
0
        public static void Main()
        {
            Dog dog = new Dog();

            dog.Bark();
            dog.Bark();

            Puppy puppy = new Puppy();

            puppy.Eat();
            puppy.Bark();
            puppy.Weep();

            Dog someDog = new Dog();

            someDog.Eat();
            someDog.Bark();
            Cat cat = new Cat();

            cat.Eat();
            cat.Meow();
        }
Beispiel #17
0
        public void Execute()
        {
            try
            {
                var dog = new Dog("Bobby");
                Console.WriteLine(dog.Bark());
                Console.WriteLine(dog.Eat());

                var puppy = new Puppy("Fluffy");
                Console.WriteLine(puppy.Eat());
                Console.WriteLine(puppy.Bark());
                Console.WriteLine(puppy.Weep());

                var cat = new Cat("Tommas");
                Console.WriteLine(cat.Eat());
                Console.WriteLine(cat.Meow());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Beispiel #18
0
    static void Main(string[] args)
    {
        var dog = new Dog();

        dog.Bark();
        dog.Eat();

        var puppy = new Puppy();

        puppy.Eat();
        puppy.Bark();
        puppy.Weep();

        var dog1 = new Dog();

        dog1.Eat();
        dog1.Bark();

        var cat = new Cat();

        cat.Eat();
        cat.Meow();
    }
Beispiel #19
0
    static void Main(string[] args)
    {
        /*
         *       Comments:
         *
         *       Shte si govorim za :
         *
         *       1.Inheritance v C# (Nasledqvane v C#)
         *       2.Class Hierarchies (klasicheska ierarhiq)
         *       3.Accessing Members of the Base Class (dostup do chlenove na bazoviq klas)
         *       4.Virtual Classes (Virtualni metodi)
         *       5.Overriding Methods (Prezapisvane na metodi)
         *       6.Generic Classess (Generic klasove i kolekcii)
         */

        /*
         * 1. Nasledqvane:
         * imame bazov klas (Base Class) (Parent Class) (SuperClass) i - predava na child klasa !
         * podklas (SubCalss) (Child Class) - vzima ot base klasa !
         *
         * podklasa moje da si ima i sobstveni dopulnitelni propertita
         *
         *
         * PRIMER: Imame klas Person() (base class) koito e nasleden ot klas Employee i klas Student (child classes)
         * No Child klasovete mogat da si imat i te sobstveni propertita
         * NASLEDQVA SE S:       : Person
         *
         *
         * V praktikata shte imamo mnogo po zadulbocheni primeri ot tova !!!
         *
         *
         *
         */


        //SEGA KLASA Dog IMA VSICHKI NESHTA OT KLASA Animal BEZ DA SME MU GI DOBAVQI.
        Dog dog = new Dog("Gafy", 9, 15);

        Console.WriteLine(dog.Name);
        Console.WriteLine(dog.Age);
        dog.Eat();



        //SEGA TOVA PUPPY IMA VSICHKO OT PREDISHNITE KLASOVE NAD NEGO.
        Puppy puppy = new Puppy("Jaky", 16, 5);

        puppy.Eat();
        puppy.Weep(); // plache


        //Kotkata nasledqva samo klasa Animal !!!
        Cat cat = new Cat("Sisa", 7, 4);

        cat.Eat();
        cat.Meaw();



        //KONSTRUKTORITE SE PREIZPOLZVAT !!!

        /*
         *  Nasledqvaneto e proces kato stupalo.
         *  NQMAME MULTIPLE INHERITANCE V C#, TRQBVA DA SA EDNO SLED DRUGO !
         *
         *  NE MOJEM PROSTO DA NAPISHEM : Puppy : Dog : Animal
         */



        /*
         *
         * S 'override' prezapisvame metodi !
         * VIRTUALNITE METODI MOGAT DA SE PREZAPISVAT !
         *
         * VIRTUALNI METODI:
         * ToString() e edin vgraden virtualen metod !
         *
         * Ponqkoga ni trqbva da mojem da promenqme metodi ot klasus koito
         * nasledqvame.
         *
         * Virtualnite metodi mogat da se promenqt
         * POZVOLQVAT NI DA GI PREZAPISVAME I DA IM PROMENQME LOGIKATA!
         * pishet se s dumata 'virtual' !
         */

        Console.WriteLine(); Console.WriteLine();
        //PRIMER :  Prezapisvame metoda Eating za vseki klas
        //Prezapisahme virtualniq metod ot klasa Animal !!!
        dog.Eat(); // pokazva Dog Eating ...
        puppy.Eat();
        cat.Eat();

        Animal animal = new Animal("Lion", 20, 250);

        animal.Eat(); // pokazva Animal Eating ...



        /*
         *  Interfeisi:
         *  Te sa neshto kato klasove
         *  i se krushtavat zpochvaiki s 'I' i polse sushtestvitelno .
         *  Primerno :
         *  1.IList t.e. sudurja samo spisuci,
         *  2.IDictionary t.e. sudurja samo rechnici.
         *
         *  public interface IMovable
         *  {
         *      . . .
         *  }
         *
         */

        // Tuk si izvikvame metoda koito polzva interfeisa IMovable koito suzdadohme
        MoveObject(cat, 10);



        /*
         * Generic Collections:
         *
         * tuk govorim za system.collection.generic
         * TE SA KATO PLACEHOLDERI KOITO POLZVAME Z DA SLAGAME TIPOVE DANNI,
         * Mojem da si slagame kakuvto tip danni si iskame, DAJE I KLASOVE KOITO
         * SME SI NAPRAVILI MOGAT DA SA TIPOVE DANNI I MOJEM DA PRAVIM KOLEKCII OT TQH !!!
         *
         *
         */

        /*SUMMARY:
         * 1.Nasledqvaneto e nestho mnogo nujno i polezno.
         *  Imame base class i child class.
         *  Child klasovete mogat da prezapisvat virtualni metodi ot baze klasa.
         * 2.interfeisa e kato dokument koito ni pokazva koi klaza za kakvo e, ulesnqva ni rabotata.
         *
         * 3.Generic kolekciite sa konteineri za vsqkauv tip danni daje i pt tip klas koito sme suzdali.
         *  Ne mojem da im slagame drug tip danni ot tozi koito sme im zadali.
         *
         *
         */
    }
Beispiel #20
0
    static void Main(string[] args)
    {
        Animal puppy = new Puppy();

        puppy.Eat();
    }
Beispiel #21
0
 static void Main(string[] args)
 {
     Animal animal;
     Console.WriteLine("Would you raise a tiger or a puppy?");
     Console.WriteLine("1 = tiger, 2 = puppy");
     int choice2;
     again:
     try
     {
         choice2 = int.Parse(Console.ReadLine());
     }
     catch (Exception)
     {
         goto again;
     }
     switch (choice2)
     {
         case 1:
             animal = new Tiger();
             break;
         case 2:
             animal = new Puppy();
             break;
         default:
             goto again;
     }
     int choice = 0;
     while (animal.isAlive())
     {
         try_again:
         Console.WriteLine("Animal status age "+ animal.Age+" fullness "+ animal.Fullness+" happiness "+ animal.Happiness);
         Console.WriteLine("1 Drink");
         Console.WriteLine("2 Eat");
         Console.WriteLine("3 Pee");
         Console.WriteLine("4 Stay");
         Console.WriteLine("5 Sit");
         Console.WriteLine("6 Pet");
         Console.WriteLine("7 MakeSound");
         Console.WriteLine("8 Mood");
         try
         {
             choice = int.Parse(Console.ReadLine());
         }
         catch (Exception)
         {
             goto try_again;
         }
         switch (choice)
         {
             case 1:
                 animal.Drink();
                 break;
             case 2:
                 animal.Eat();
                 break;
             case 3:
                 animal.Pee();
                 break;
             case 4:
                 animal.Stay();
                 break;
             case 5:
                 animal.Sit();
                 break;
             case 6:
                 animal.Pet();
                 break;
             case 7:
                 animal.MakeSound();
                 break;
             case 8:
                 Console.WriteLine(animal.Mood());
                 break;
         }
         goto try_again;
     }
 }