Beispiel #1
0
        static void Main(string[] args)
        {
            var cow = new Cow(new Moo()); //moo is in a different namespace, be sure to add it.

            cow.Speak();

            var cat = new Cat(new Meow());

            cat.Speak();

            var david = new David(new MeoOOO()); //is it a cow with cat legs?

            david.Speak();

            var animals = new List <ISpeak>();

            animals.Add(cat);
            animals.Add(cow);
            animals.Add(david);

            foreach (var animal in animals)
            {
                animal.Speak();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var cow = new Cow(new Moo());

            cow.Speak();

            var cat = new Cat(new Meow());

            cat.Speak();

            var cot = new Cot(new Meoo());

            cot.Speak();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Cox Farm.");
            Pig pig1 = new Pig("Pig1");

            pig1.Speak("Pig1's language");
            pig1.Eat("Pig1's food");
            Pig pig2 = new Pig("Pig2");

            pig2.Speak("Pig2's language");
            pig2.Eat("Pig2's food");
            Pig pig3 = new Pig();

            pig3.Speak("'Heng Heng!'");
            pig3.Eat("Swill");
            Console.WriteLine();
            Cow cow1 = new Cow("Cow1");

            cow1.Speak("Cow1's language");
            cow1.Eat("Cow1's food");
            Cow cow2 = new Cow("Cow2");

            cow2.Speak("Cow2's language");
            cow2.Eat("Cow2's food");
            Cow cow3 = new Cow();

            cow3.Speak("'Mer~'");
            cow3.Eat("Grass");
            Console.WriteLine();
            Chicken chicken1 = new Chicken("Chicken1");

            chicken1.Speak("Chicken1's language");
            chicken1.Eat("Chicken1's food");
            Chicken chicken2 = new Chicken("Chicken2");

            chicken2.Speak("Chicken2's language");
            chicken2.Eat("Chicken2's food");
            Chicken chicken3 = new Chicken();

            chicken3.Speak("'Gu Gu Gu...'");
            chicken3.Eat("Millet");
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var cow = new Cow(new Moo());

            cow.Speak();
            var cat = new Cat(new Meow());

            cat.Speak();
            var catcow = new CatCow(new MeowMoo());

            catcow.Speak();

            var animals = new List <ISpeak>();                  //define collection, use interface as type

            animals.Add(cat);
            animals.Add(cow);
            animals.Add(catcow);

            foreach (var animal in animals)
            {
                animal.Speak();
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            string input;

            //Display Header
            Console.WriteLine();
            Console.WriteLine("********************************** WELCOME TO SOUTHEAST AMIMAL FARM ******************************************" + "\n\n");
            Console.WriteLine(" Instruction \n" + " To visit each animal section type a keyword :");
            Console.WriteLine(" chicken\n" + " cow\n" + " horse\n" + " pig\n\n");

            //Add dictionary data structure to match the keyword with display section
            Dictionary <string, string> keyword = new Dictionary <string, string>();

            keyword.Add("chicken", "********************* WELCOME TO CHICKEN SECTION **************************");
            keyword.Add("cow", "*********************WELCOME TO COW SECTION ***************************");
            keyword.Add("horse", "********************* WELCOME TO HORSE SECTION **************************");
            keyword.Add("pig", "********************* WELCOME TO PIG SECTION **************************");

            //Convert the dictionary to IEnumerable collection
            var element = keyword.ToList();

            do
            {
GoBack:
                Console.Write("Enter a keyword to visit a section of the farm or type 'quit' to exit : ");
                input = Console.ReadLine();
                Console.WriteLine("\n\n");


                if ((input == "chicken") && (element[0].Key == "chicken"))
                {
                    Console.WriteLine(element[0].Value);

                    //Add Margin between objects
                    Console.WriteLine("\n\n");

                    Animal chicken = new Chicken();

                    Console.Write("Enter animal name: ");
                    chicken.AnimalName = Console.ReadLine();

                    chicken.Speak();
                    chicken.Eat();
                    chicken.Product();
                }
                else if ((input == "cow") && (element[1].Key == "cow"))
                {
                    Console.WriteLine(element[1].Value);

                    //Add Margin between objects
                    Console.WriteLine("\n\n");

                    Animal cow = new Cow();

                    Console.Write("Enter animal name: ");
                    cow.AnimalName = Console.ReadLine();

                    cow.Speak();
                    cow.Eat();
                    cow.Product();
                }
                else if ((input == "horse") && (element[2].Key == "horse"))
                {
                    Console.WriteLine(element[2].Value);

                    //Add Margin between objects
                    Console.WriteLine("\n\n");

                    Animal horse = new Horse();

                    Console.Write("Enter animal name: ");
                    horse.AnimalName = Console.ReadLine();

                    horse.Speak();
                    horse.Eat();
                    horse.Product();
                }
                else if ((input == "pig") && (element[3].Key == "pig"))
                {
                    Console.WriteLine(element[3].Value);

                    //Add Margin between objects
                    Console.WriteLine("\n\n");

                    Animal pig = new Pig();

                    Console.Write("Enter animal name: ");
                    pig.AnimalName = Console.ReadLine();

                    pig.Speak();
                    pig.Eat();
                    pig.Product();
                }
                else if (input == "quit")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid Keyword! Try again!\n");
                    goto GoBack;
                }
            } while (input != "quit");
            Console.ReadKey();
        }