Exemplo n.º 1
0
        private static void makePig(string newPig, string Pun)
        {
            Pig    P    = new Pig(newPig);
            string talk = P.Speak();
            string roll = P.Play();

            Console.WriteLine($"{newPig} says: {talk}, and {roll}");
            Console.WriteLine($"{newPig} says: {Pun}");
            Console.ResetColor();
            Console.ReadLine();
        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
0
        public static void CreateFarmAnimals()
        {
            try
            {
                Horse myHorse = new Horse("Mr.ED");
                myHorse.MakeNoise();
                //myHorse.Eat();
                myHorse.Product();
                //myHorse.Sleep();

                Cow myCow = new Cow("Daisy");
                myCow.MakeNoise();
                //myCow.Eat();
                myCow.Product();
                //myCow.Sleep();

                Pig myPig = new Pig("Porky");
                myPig.MakeNoise();
                //myPig.Eat();
                myPig.Product();
                //myPig.Sleep();

                Sheep mySheep = new Sheep("Daisy");
                mySheep.MakeNoise();
                //mySheep.Eat();
                mySheep.Product();
                //mySheep.Sleep();
            }
            catch (Exception ex)              //Handles any execption thrown
            {
                Console.WriteLine(ex.Message);
                CreateFarmAnimals();
            }
            finally
            {
                Console.WriteLine("These were my animal farms.");
            }
        }
Exemplo n.º 4
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();
        }