Example #1
0
        public static void Main()
        {
            Car         car1    = new Car();
            Motorcycle  moto1   = new Motorcycle();
            Cessna      cessna1 = new Cessna();
            Helicopter  heli1   = new Helicopter();
            JetSki      jetski1 = new JetSki();
            FishingBoat fish1   = new FishingBoat();

            // Build a collection of all vehicles that fly

            List <IAirCraft> flyingVehicles = new List <IAirCraft>()
            {
            };

            flyingVehicles.Add(cessna1);
            flyingVehicles.Add(heli1);

            // With a single `foreach`, have each vehicle Fly()

            foreach (IAirCraft vehicle in flyingVehicles)
            {
                vehicle.Fly();
            }

            // Build a collection of all vehicles that operate on roads

            List <ILandCraft> landVehicles = new List <ILandCraft>()
            {
            };

            landVehicles.Add(moto1);
            landVehicles.Add(car1);

            // With a single `foreach`, have each road vehicle Drive()

            foreach (ILandCraft vehicle in landVehicles)
            {
                vehicle.Drive();
            }

            // Build a collection of all vehicles that operate on water

            List <IVehicle> waterVehicles = new List <IVehicle>()
            {
            };

            waterVehicles.Add(jetski1);
            waterVehicles.Add(fish1);

            // With a single `foreach`, have each water vehicle Drive()

            foreach (IVehicle vehicle in landVehicles)
            {
                vehicle.Drive();
            }
        }
Example #2
0
        public static void Main()
        {
            // Build a collection of all vehicles that fly
            Cessna          charlieCessna = new Cessna();
            SeaPlane        littleMermaid = new SeaPlane();
            SevenFortySeven flight919     = new SevenFortySeven();

            charlieCessna.Name = "Charlie";
            littleMermaid.Name = "Little Mermaid";
            flight919.Name     = "Flight 919";

            List <Flyers> thingsThatFly = new List <Flyers>();

            thingsThatFly.Add(charlieCessna);
            thingsThatFly.Add(littleMermaid);
            thingsThatFly.Add(flight919);

            // With a single `foreach`, have each vehicle Fly()

            foreach (Flyers flight in thingsThatFly)
            {
                System.Console.WriteLine($"{flight.Name} has {flight.Fly()}");
            }

            // Build a collection of all vehicles that operate on roads
            List <Drivers> thingsThatDrive = new List <Drivers>()
            {
                new Motorcycle()
                {
                    Name = "Rita",
                    Type = "Motorcycle"
                },
                new Jeep()
                {
                    Name = "Dad's Jeep",
                    Type = "JEEP"
                },
                new Amphicar()
                {
                    Name = "Big Mermaid",
                    Type = "Aqua Car"
                },
            };

            // With a single `foreach`, have each road vehicle Drive()

            foreach (Drivers thing in thingsThatDrive)
            {
                System.Console.WriteLine($"{thing.Name} the {thing.Type} is {thing.Drive()} with its {thing.Wheels} wheels");
            }


            // Build a collection of all vehicles that operate on water

            // With a single `foreach`, have each water vehicle Drive()
        }
Example #3
0
        public static void Main()
        {
            // Build a collection of all vehicles that fly
            List <IAirVehicle> aircraft = new List <IAirVehicle>();

            Cessna c172 = new Cessna()
            {
                Winged            = true,
                MaxAirSpeed       = 239,
                Doors             = 1,
                PassengerCapacity = 4,
                EngineVolume      = 29,
            };

            Helicopter lifeFlight = new Helicopter()
            {
                Winged            = false,
                MaxAirSpeed       = 200,
                Doors             = 2,
                PassengerCapacity = 3,
                EngineVolume      = 29,
            };

            aircraft.Add(lifeFlight);
            aircraft.Add(c172);

            // With a single `foreach`, have each vehicle Fly()
            foreach (IAirVehicle a in aircraft)
            {
                a.Fly();
            }


            // Build a collection of all vehicles that operate on roads
            List <ILandVehicle> landRovers = new List <ILandVehicle>();

            Motorcycle Bmw = new Motorcycle()
            {
                MaxLandSpeed      = 219,
                Doors             = 0,
                PassengerCapacity = 2,
                TransmissionType  = "Manual",
                EngineVolume      = 20,
                Wheels            = 2,
            };

            Motorcycle Harley = new Motorcycle()
            {
                MaxLandSpeed      = 180,
                Doors             = 0,
                PassengerCapacity = 2,
                TransmissionType  = "Manual",
                EngineVolume      = 25,
                Wheels            = 2,
            };

            landRovers.Add(Harley);
            landRovers.Add(Bmw);

            // With a single `foreach`, have each road vehicle Drive()
            foreach (ILandVehicle l in landRovers)
            {
                l.Drive();
            }


            // Build a collection of all vehicles that operate on water
            List <IWaterVehicle> waterCrafts = new List <IWaterVehicle>();
            JetSki Kawasaki = new JetSki()
            {
                MaxWaterSpeed     = 45.00,
                Doors             = 0,
                PassengerCapacity = 1,
                EngineVolume      = 10.00,
            };

            Submarine u584 = new Submarine()
            {
                MaxWaterSpeed     = 150.00,
                Doors             = 2,
                PassengerCapacity = 6,
                EngineVolume      = 2.00,
            };

            waterCrafts.Add(Kawasaki);
            waterCrafts.Add(u584);

            // With a single `foreach`, have each water vehicle Drive()
            foreach (IWaterVehicle w in waterCrafts)
            {
                w.Drive();
            }
        }