Answer to Question #264374 in C# for T.Aparna

Question #264374

We are starting a new children's entertainment software company

Our first application will be old Macdonald's farm

Initially children can put three types of animals


1
Expert's answer
2021-11-11T07:59:06-0500
 static void Main(string[] args)
        {
            Farm<Animal> farm = new Farm<Animal>();
            farm.Animals.Add(new Cow("Jack"));
            farm.Animals.Add(new Chicken("Vera"));
            farm.Animals.Add(new Chicken("Sally"));
            farm.Animals.Add(new SuperCow("Kevin"));
            farm.MakeNoises();

            Farm<Cow> dairyFarm = farm.GetCows();
            dairyFarm.FeedTheAnimals();

            foreach (Cow cow in dairyFarm)
            {
                if (cow is SuperCow)
                {
                    (cow as SuperCow).Fly();
                }
            }
            Console.ReadKey();

            #region Code for "Generic Operators" section
            //Farm<Animal> newFarm = farm + dairyFarm;
            #endregion

            #region Code for "Generic Operators" section
            //Farm<Cow> anotherDairyFarm = farm.GetSpecies<Cow>();
            //Farm<Chicken> poultryFarm = farm.GetSpecies<Chicken>();
            #endregion
        } 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS