Ejemplo n.º 1
0
        public void ConstructorTests()
        {
            Animal casey = new Animal();

            casey.Move();

            Console.WriteLine();

            Cat mittens = new Cat();

            mittens.Move();
            mittens.MakeSound();

            Console.WriteLine();

            Cat content = new Liger();

            content.Move();
            content.MakeSound();

            Liger garfield = (Liger)content;

            garfield.TeethSize = "Kinda large";

            Console.WriteLine();

            Liger billyJoel = new Liger();

            billyJoel.Move();
            billyJoel.MakeSound();

            billyJoel.TeethSize = "Reeallly big.";
        }
Ejemplo n.º 2
0
        public void ConstructorTests()
        {
            Animal casey = new Animal();

            casey.Move();

            Console.WriteLine();

            Cat mittens = new Cat();

            mittens.Move();
            mittens.MakeSound();

            Console.WriteLine();

            Cat content = new Liger();

            content.Move();
            content.MakeSound();

            // content and garfield are both referencing Liger object, but content is Cat type and garfield is Liger type

            Liger garfield = (Liger)content;

            //              casting content as a Liger
            garfield.TeethSize = "Kinda large";

            Console.WriteLine();

            Liger billieJoel = new Liger();

            billieJoel.Move();
            billieJoel.MakeSound();
            billieJoel.TeethSize = "Reeeally big.";
        }
Ejemplo n.º 3
0
        public void TestMethod1()
        {
            Cat firstCat = new Cat();

            firstCat.MakeSound();
            firstCat.Move();

            Liger firstLiger = new Liger();

            firstLiger.MakeSound();
            firstLiger.Move();
        }
Ejemplo n.º 4
0
        public void CatTesting()
        {
            Animal firstAnimal = new Animal();
            Cat    firstCat    = new Cat();

            firstAnimal.Move();
            firstCat.Move();
            firstCat.MakeSound();

            Liger oneLiger = new Liger();

            oneLiger.Move();
            oneLiger.MakeSound();
        }
Ejemplo n.º 5
0
        public void CatTesting()
        {
            Animal firstAnimal = new Animal();

            Console.WriteLine("Break after animal");
            Cat firstCat = new Cat();

            firstAnimal.Move();
            firstCat.Move();
            firstCat.MakeSound();

            Liger oneLiger = new Liger();

            oneLiger.Move();
            oneLiger.MakeSound();
        }
Ejemplo n.º 6
0
        public void TestMethod1()
        {
            Cat firstCat = new Cat();

            firstCat.MakeSound();
            firstCat.Move();

            Liger firstLiger = new Liger();

            firstLiger.MakeSound();
            firstLiger.Move();

            List <Animal> test = new List <Animal>();

            test.Add(firstCat);
            test.Add(firstLiger);
        }
        public void CatTesting()
        {
            Cat firstCat = new Cat();

            firstCat.Move();
            firstCat.MakeSound();

            Liger oneLiger = new Liger();

            List <Animal> allAnimals = new List <Animal>();

            allAnimals.Add(firstCat);
            allAnimals.Add(oneLiger);
            oneLiger.Move();
            oneLiger.MakeSound();
            //Try making other classes that inherit from animal class
        }
Ejemplo n.º 8
0
        public void CatTesting()
        {
            //Animal firstAnimal = new Animal();
            Console.WriteLine("Break");
            Cat firstCat = new Cat();

            Console.WriteLine("Break");
            //firstAnimal.Move();
            Console.WriteLine("Break");
            firstCat.Move();
            Console.WriteLine("Break");
            firstCat.MakeSound();
            Console.WriteLine("Break");
            Liger oneLiger = new Liger();

            Console.WriteLine("Break");
            oneLiger.Move();
            Console.WriteLine("Break");
            oneLiger.MakeSound();
            //Try making other classes that inherit from the animal class
        }
Ejemplo n.º 9
0
        public void TestMethod1()
        {
            Cat firstCat = new Cat();

            firstCat.MakeSound();
            firstCat.Move();

            Liger firstLiger = new Liger();

            firstLiger.MakeSound();
            firstLiger.Move();

            List <Animal> test = new List <Animal>();

            test.Add(firstCat);
            test.Add(firstLiger);


            Animal oneAnimal = new Animal();

            oneAnimal.BreathsAir = false;
        }
Ejemplo n.º 10
0
        public void TestMethod1()
        {
            // ctrl . to connect/reference the Cat to the Cat file
            // newing up the belwo infomation
            Cat firstCat = new Cat();

            firstCat.MakeSound();
            firstCat.Move();

            //doing it for liger now referencing and newing up stff

            Liger firstLiger = new Liger();

            firstLiger.MakeSound();
            firstLiger.Move();

            // connected the list with animial to cat and liger
            List <Animal> test = new List <Animal>();

            test.Add(firstCat);
            test.Add(firstLiger);
        }
Ejemplo n.º 11
0
        public void TestMethod1()
        {
            Animal firstAnimal = new Animal();

            firstAnimal.LegCount = 4; //cannot access sloth props, only its own


            Sloth sloth = new Sloth();

            sloth.LegCount = 4;        //CAN access animal props and its own
            bool value = sloth.IsSlow; //cant declare, must set to variable as it already has a unchanging value

            Megatherium giantSloth = new Megatherium();

            giantSloth.HasTail   = false;
            giantSloth.IsExtinct = true;

            Cat firstCat = new Cat();

            firstCat.MakeSound(); //Meow

            Liger liger = new Liger();

            liger.MakeSound(); //hover shows Liger.MakeSound only, not Cat.MakeSound
            Cheetah chee = new Cheetah();

            chee.MakeSound(); //Purr.
            //chee is purr here, but not below as a Cat type

            List <Cat> catList = new List <Cat>(); //works with Animal too, but not Sloths

            catList.Add(firstCat);
            catList.Add(liger);
            catList.Add(chee);                              //works, happy

            List <Animal> animalList = new List <Animal>(); //works with cats, and sloths

            animalList.Add(firstCat);
            animalList.Add(liger);
            animalList.Add(chee);
            animalList.Add(giantSloth);

            foreach (Animal animal in animalList)
            {
                //cant call MakeSound() because not all animals have MakeSound
                //can only call Animal properties, not children properties
            }

            //foreach(Cat animal in animalList) //doesnt work, gets stuck at non-Cats
            //{
            //    animal.MakeSound();
            //}
            foreach (Animal animal in animalList)
            {
                //if(animal.GetType() == typeof(Cat)) //Must be Cat type! Liger and Cheetah types wont count as Cat! and skips
                if (animal is Cat) //works with Cat and children of Cat (ie Liger and Cheetah) but not Sloth etc
                {
                    //casting yay!
                    Cat cat = (Cat)animal;
                    //cant do above if type isnt already Cat (ex. sloths)
                    //if using (animal is Cat), casting still retains Liger as Liger, etc
                    cat.MakeSound(); //so cat meows and liger still roars
                    //Cheetah didnt purr, because it called original MakeSound, not new MakeSound
                    //new made method unrelated to original MakeSound;
                }
            }
        }