Пример #1
0
    public static void Main()
    {
        FlyingSquirrel rocky = new FlyingSquirrel();
        Eagle          sam   = new Eagle();

        List <IWalking> birds = new List <IWalking>();

        //type squirrel , class squirrel
        birds.Add(sam);
        //type eagle, class eagle
        birds.Add(rocky);

        // the foreach will loop through rocky-type FlyingSquirrel , sam-type Eagle
        foreach (var thing in birds)
        {
            //each thing has a type or class, will refer to the method fly in that specific class
            // fly method consoles a message
            // thing.Fly();
            thing.Walk();
        }
        sam.Fly();
        sam.Walk();
        sam.AirSpeed = 5;
        Console.WriteLine($"sam's airspeed {sam.AirSpeed}");
    }
Пример #2
0
        static void Main(string[] args)
        {
            FlyingSquirrel scrat = new FlyingSquirrel
            {
                name = "Scrat"
            };

            scrat.species = new TenoderaAngustipennis();

            Console.WriteLine("{0} the {1} in the genus {2}. To find out more visit {3}.",
                              scrat.name,
                              scrat.species.commonName,
                              scrat.species.genus.scientificName,
                              scrat.species.url);
        }
Пример #3
0
    public static void Main()
    {
        FlyingSquirrel rocky = new FlyingSquirrel();
        Eagle          sam   = new Eagle();

        List <IFlying> birds = new List <IFlying>();

        birds.Add(sam);
        birds.Add(rocky);

        foreach (var thing in birds)
        {
            thing.Fly();
        }
    }
Пример #4
0
        static void Main(string[] args)
        {
            Savanna savanna = new Savanna();

            savanna.inhabitants = new List <Animal>();


            Aquarium aquarium = new Aquarium();

            Pool sealPool = new Pool();


            ReptileHouse snakePit = new ReptileHouse();


            Aviary aviary = new Aviary();


            Mantis manny = new Mantis();

            manny.name    = "Manny";
            manny.species = new TenoderaAngustipennis();

            Mantis danny = new Mantis();

            danny.name    = "Danny";
            danny.species = new TenoderaSinensis();

            FlyingSquirrel scrat = new FlyingSquirrel();

            scrat.name    = "Scrat";
            scrat.species = new TenoderaAngustipennis();


            savanna.inhabitants.Add(manny);
            savanna.inhabitants.Add(danny);
            savanna.inhabitants.Add(scrat);

            foreach (Animal a in savanna.inhabitants)
            {
                Console.WriteLine("{0} the {1} in the genus {2}. To find out more visit {3}.",
                                  a.name,
                                  a.species.commonName,
                                  a.species.genus.scientificName,
                                  a.species.url);
            }
        }
        static void Main(string[] args)
        {
            // Create an savanna habitat and
            Savanna savanna = new Savanna();

            savanna.inhabitants = new List <Animal>();
            savanna.name        = "African Grasslands";

            // Create an aquarium habitat
            Aquarium aquarium = new Aquarium();

            aquarium.name = "Coral Reef";

            // Create a pool habitat
            Pool sealPool = new Pool();

            sealPool.name = "California Coast";

            // Create a snake pit habitat
            ReptileHouse snakePit = new ReptileHouse();

            snakePit.name = "Snake Pit";

            // Create an aviary habitat
            Aviary aviary = new Aviary();

            aviary.name = "Tropical Canopy";

            // Create the Zoo and add all the habitats to it
            Zoo zoolandia = new Zoo();

            zoolandia.habitats.Add(aviary);
            zoolandia.habitats.Add(savanna);
            zoolandia.habitats.Add(aquarium);
            zoolandia.habitats.Add(sealPool);
            zoolandia.habitats.Add(snakePit);

            // Create some animals
            Mantis manny = new Mantis();

            manny.name    = "Manny";
            manny.species = new TenoderaAngustipennis();

            Mantis danny = new Mantis();

            danny.name    = "Danny";
            danny.species = new TenoderaSinensis();

            FlyingSquirrel scrat = new FlyingSquirrel();

            scrat.name     = "Scrat";
            scrat.species  = new Pteromyini();
            scrat.airSpeed = 4;
            // scrat.fly();

            // Add the sample animals to the savanna habitat
            savanna.inhabitants.Add(manny);
            savanna.inhabitants.Add(danny);
            savanna.inhabitants.Add(scrat);

            // Output the habitats in our Zoo
            Console.WriteLine($"\nHabitats in `{zoolandia.marketingReport()}`\n===================================");
            foreach (Habitat habitat in zoolandia.habitats)
            {
                Console.WriteLine($"{habitat.name}");
            }

            // Iterate over the inhabitants of the savanna habitat and output
            // info to the console
            foreach (Animal a in savanna.inhabitants)
            {
                Console.WriteLine($@"
{a.name} the {a.species.commonName} in the genus {a.species.genus.scientificName}.
To find out more visit {a.species.url}.");
            }
        }