Ejemplo n.º 1
0
        public static void Main()
        {
            // Build a collection of all vehicles that fly
            var cessna = new Cessna();
            var archer = new PiperArcher();

            var airVehicles = new List <IAircraft> {
                cessna, archer
            };

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

            foreach (var aircraft in airVehicles)
            {
                aircraft.Start();
                aircraft.Fly();
                aircraft.Stop();
                Console.ReadLine();
            }



            // Build a collection of all vehicles that operate on roads
            var motorcycle = new Motorcycle();
            var ambulance  = new Ambulance();

            var landVehicles = new List <ILandCraft> {
                motorcycle, ambulance
            };

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

            foreach (var vehicle in landVehicles)
            {
                vehicle.Start();
                vehicle.Drive();
                vehicle.Stop();
                Console.ReadLine();
            }



            // Build a collection of all vehicles that operate on water
            var jetSki = new JetSki();
            var ferry  = new Ferry();

            var waterVehicles = new List <IWaterCraft> {
                ferry, jetSki
            };

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

            foreach (var waterCraft in waterVehicles)
            {
                waterCraft.Start();
                waterCraft.Drive();
                waterCraft.Stop();
                Console.ReadLine();
            }
        }
Ejemplo n.º 2
0
    public static void Main()
    {
        List <IWaterVehicle> waterVehicles = new List <IWaterVehicle>();

        MasterCraft myBoat      = new MasterCraft(10, "good transmission", 68.0, 87.0);
        Pontoon     mySlowBoat  = new Pontoon(16, "old transmission", 44.0, 13.0);
        JetSki      mySpeedBoat = new JetSki(2, "awesome transmission", 30.0, 100.99);

        waterVehicles.Add(myBoat);
        waterVehicles.Add(mySlowBoat);
        waterVehicles.Add(mySpeedBoat);

        waterVehicles.ForEach(vehicle =>
        {
            vehicle.Start();
            vehicle.Drive();
            vehicle.Stop();
        });
        // Build a collection of all vehicles that fly

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



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

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



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

        // With a single `foreach`, have each water vehicle Drive()
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Form1 class
        /// </summary>
        public Form1()
        {
            InitializeComponent();

            WaterCraft jetski = new JetSki();

            jetski = new TrailerDecorater(jetski);

            Console.WriteLine(jetski.Description);
            Console.WriteLine("Price: {0}", jetski.RetailPrice);

            #region [Panels]
            PHome.Visible              = true;
            PanelInvent.Visible        = false;
            PanelViewInventory.Visible = false;
            #endregion

            #region [Populate list box with inventory]
            Inventory.Add("Canoes", new List <WaterCraft>());
            Inventory["Canoes"].Add(new Canoe("C-5001", 9000, "Adventure 16", Canoe.CBrand.Blue_Water_Canoe, Canoe.CType.Classic_Wood, Canoe.PType.Lakewater));
            Inventory["Canoes"].Add(new Canoe("C-5001", 7000, "Winter Odyssey", Canoe.CBrand.Mad_River_Canoe, Canoe.CType.Expendtion, Canoe.PType.Recreational));
            Inventory["Canoes"].Add(new Canoe("CA-1000", 8500, "Trek - 14", Canoe.CBrand.Mohawk_Canoe, Canoe.CType.Recreation, Canoe.PType.Recreational));
            Inventory["Canoes"].Add(new Canoe("CZ- 01", 9500, "T90 Z", Canoe.CBrand.Clipper_Canoe, Canoe.CType.Sporting, Canoe.PType.Whitewater));

            Inventory.Add("Sailing Yachts", new List <WaterCraft>());
            Inventory["Sailing Yachts"].Add(new SailingYacht("SY-550", "Testing Sailing Yachts 1", 25, 10000, 15000, SailingYacht.SYType.Cruising, SailingYacht.SYBrand.Catalina));
            Inventory["Sailing Yachts"].Add(new SailingYacht("SY-800", "Beery Racing", SailingYacht.SYBrand.LaurieDavidson, SailingYacht.SYType.Racing, 50000));
            Inventory["Sailing Yachts"].Add(new SailingYacht("SY-990", "Bling Bling", SailingYacht.SYBrand.Sydney, SailingYacht.SYType.Luxury, 100000));
            Inventory["Sailing Yachts"].Add(new SailingYacht("SA-000", "Wind Chaser SZ", SailingYacht.SYBrand.Farr, SailingYacht.SYType.Weekender, 30000));

            Inventory.Add("Motor Yachts", new List <WaterCraft>());
            Inventory["Motor Yachts"].Add(new MotorYacht("MY-3000", 30000, "YST MAX", MotorYacht.MYBrand.Lazzarra, MotorYacht.MYType.Sport_Fishing, 5, 10));
            Inventory["Motor Yachts"].Add(new MotorYacht("MY-5000", 500000, "World Lux -30W", MotorYacht.MYBrand.Royal_Huisman, MotorYacht.MYType.Luxury, 10, 25));
            Inventory["Motor Yachts"].Add(new MotorYacht("MZ-2000", 40999, "A-9000", MotorYacht.MYBrand.Azimut, MotorYacht.MYType.Sport_Fishing, 2, 3));

            Inventory.Add("Jet Skis", new List <WaterCraft>());
            Inventory["Jet Skis"].Add(new JetSki("JS-550", 5000, "Ultra 310R", JetSki.JSBrand.Yamaha, JetSki.JStype.ThreeSeater, 925, 40, 5));
            Inventory["Jet Skis"].Add(new JetSki("JS-900", 8000, "Sun LX", JetSki.JSBrand.Honda, JetSki.JStype.FourSeater, 800, 55, 5));
            Inventory["Jet Skis"].Add(new JetSki("JS-900", 10000, "STX - 15F", JetSki.JSBrand.Kawasaki, JetSki.JStype.SportCraft, 957, 60, 5));
            Inventory["Jet Skis"].Add(new JetSki("JA-94A", 2000, "JS Bling", JetSki.JSBrand.Polaris, JetSki.JStype.SoloCraft, 875, 45, 10));
            #endregion

            #region [Total retail price and water crafts in inventory labels]
            decimal totalPrice = 0m;
            int     totalCount = 0;
            foreach (KeyValuePair <string, List <WaterCraft> > kvp in Inventory)
            {
                foreach (WaterCraft w in kvp.Value)
                {
                    totalPrice += w.RetailPrice;
                }
                totalCount += kvp.Value.Count;
            }
            LabelTotalPrice.Text = totalPrice.ToString("c0");
            LabelTotalCount.Text = totalCount.ToString();
            #endregion
        }
Ejemplo n.º 4
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly

        Cessna plane  = new Cessna();
        Jet    plane2 = new Jet();

        List <IAirbased> airList = new List <IAirbased>();

        airList.Add(plane);
        airList.Add(plane2);

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

        foreach (var item in airList)
        {
            item.Fly();
        }

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

        Motorcycle bike  = new Motorcycle();
        Truck      truck = new Truck();

        List <IGroundbased> groundList = new List <IGroundbased>();

        groundList.Add(bike);
        groundList.Add(truck);

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

        foreach (var item in groundList)
        {
            item.Drive();
        }

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

        JetSki  ski  = new JetSki();
        Pontoon boat = new Pontoon();

        List <IWaterbased> waterList = new List <IWaterbased>();

        waterList.Add(ski);
        waterList.Add(boat);

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

        foreach (var item in waterList)
        {
            item.Drive();
        }
    }
Ejemplo n.º 5
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        Cessna     cess172 = new Cessna();
        Cessna     cessC34 = new Cessna();
        Helicopter Chinook = new Helicopter();
        Helicopter Iriqois = new Helicopter();

        List <IFly> flying = new List <IFly>()
        {
            cess172, cessC34, Chinook, Iriqois
        };

        // With a single `foreach`, have each vehicle Fly()
        foreach (IFly thing in flying)
        {
            thing.Fly();
        }

        // Build a collection of all vehicles that operate on roads
        Van        Odyssey = new Van();
        Van        Sienna  = new Van();
        Motorcycle Yellow  = new Motorcycle();
        Motorcycle Green   = new Motorcycle();

        List <IGround> ground = new List <IGround>()
        {
            Odyssey, Sienna, Yellow, Green
        };

        // With a single `foreach`, have each road vehicle Drive()
        foreach (IGround thing in ground)
        {
            thing.Drive();
        }

        // Build a collection of all vehicles that operate on water
        Houseboat Mine   = new Houseboat();
        Houseboat Yours  = new Houseboat();
        JetSki    purple = new JetSki();
        JetSki    green  = new JetSki();

        List <IAquatic> swim = new List <IAquatic>()
        {
            Mine, Yours, purple, green
        };

        // With a single `foreach`, have each water vehicle Drive()
        foreach (IAquatic thing in swim)
        {
            thing.Drive();
        }
    }
Ejemplo n.º 6
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly

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

        Blimp  blimp1  = new Blimp();
        Cessna cessna1 = new Cessna();

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

        thingsThatFly.Add(blimp1);
        thingsThatFly.Add(cessna1);

        foreach (IAirBased thing in thingsThatFly)
        {
            thing.Fly();
        }

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

        // With a single `foreach`, have each road vehicle Drive()
        Motorcycle  motorcycle1 = new Motorcycle();
        PickupTruck truck1      = new PickupTruck();

        List <IVehicle> thingsOnRoad = new List <IVehicle>();

        thingsOnRoad.Add(motorcycle1);
        thingsOnRoad.Add(truck1);

        foreach (IVehicle thing in thingsOnRoad)
        {
            thing.Drive();
        }


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

        // With a single `foreach`, have each water vehicle Drive()
        JetSki  jet1 = new JetSki();
        Pontoon pon1 = new Pontoon();

        List <IVehicle> thingsOnWater = new List <IVehicle>();

        thingsOnWater.Add(jet1);
        thingsOnWater.Add(pon1);

        foreach (IVehicle thing in thingsOnWater)
        {
            thing.Drive();
        }
    }
Ejemplo n.º 7
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        HotAirBalloon balloon1 = new HotAirBalloon();
        HotAirBalloon balloon2 = new HotAirBalloon();

        List <IAirbased> flyingstuff = new List <IAirbased>();

        flyingstuff.Add(balloon1);
        flyingstuff.Add(balloon2);

        // With a single `foreach`, have each vehicle Fly()
        foreach (IAirbased item in flyingstuff)
        {
            item.Fly();
        }

        // Build a collection of all vehicles that operate on roads
        Motorcycle motorcycle1 = new Motorcycle();
        Motorcycle motorcycle2 = new Motorcycle();
        Hatchback  hondafit    = new Hatchback();
        Cessna     planecar    = new Cessna();

        List <IGroundbased> groundstuff = new List <IGroundbased>();

        groundstuff.Add(motorcycle1);
        groundstuff.Add(motorcycle2);
        groundstuff.Add(hondafit);
        groundstuff.Add(planecar);

        // With a single `foreach`, have each road vehicle Drive()
        foreach (IGroundbased item in groundstuff)
        {
            item.Drive();
        }

        // Build a collection of all vehicles that operate on water
        JetSki jetski1 = new JetSki();
        JetSki jetski2 = new JetSki();

        List <IWaterbased> waterstuff = new List <IWaterbased>();

        waterstuff.Add(jetski1);
        waterstuff.Add(jetski2);

        // With a single `foreach`, have each water vehicle Drive()
        foreach (IWaterbased item in waterstuff)
        {
            item.Drive();
        }
    }
Ejemplo n.º 8
0
    public static void Main()
    {
        var motorcycle = new Motorcycle();
        var tricycle   = new Tricycle();
        var jetski     = new JetSki();
        var submarine  = new Submarine();
        var cessna     = new Cessna();
        var paraglider = new Paraglider();


        // Build a collection of all vehicles that fly
        var flyers = new List <IAirVehicle>();

        flyers.Add(cessna);
        flyers.Add(paraglider);

        // With a single `foreach`, have each vehicle Fly()
        foreach (var plane in flyers)
        {
            plane.Fly();
        }


        // Build a collection of all vehicles that operate on roads
        var drivers = new List <IGroundVehicle>();

        drivers.Add(motorcycle);
        drivers.Add(tricycle);

        // With a single `foreach`, have each road vehicle Drive()
        foreach (var ride in drivers)
        {
            ride.Drive();
        }



        // Build a collection of all vehicles that operate on water
        var swimmers = new List <IWaterVehicle>();

        swimmers.Add(jetski);
        swimmers.Add(submarine);

        // With a single `foreach`, have each water vehicle Drive()
        foreach (var fish in swimmers)
        {
            fish.Drive();
        }

        Console.ReadLine();
    }
Ejemplo n.º 9
0
        public static void Main()
        {
            // Build a collection of all vehicles that fly
            var jet        = new Jet(200, 250, ColorOfVehicle.Silver);
            var helecopter = new Helecoptor(150, 4, ColorOfVehicle.Black);

            List <AirCraft> aircrafts = new List <AirCraft>();

            aircrafts.Add(jet);
            aircrafts.Add(helecopter);


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

            // Build a collection of all vehicles that operate on roads
            var fordtruck = new FordTruck(12, 5, ColorOfVehicle.Black);
            var fastcar   = new FastCar(20, 5, ColorOfVehicle.Blue);

            List <Car> cars = new List <Car>();

            cars.Add(fordtruck);
            cars.Add(fastcar);

            // With a single `foreach`, have each road vehicle Drive()
            foreach (var car in cars)
            {
                car.Driving(50);
            }

            // Build a collection of all vehicles that operate on water
            var jetski = new JetSki(10, 1, ColorOfVehicle.MotherOfPearl);
            var boat   = new Boat(0, 5, ColorOfVehicle.Blue);

            List <WaterCraft> watercrafts = new List <WaterCraft>();

            watercrafts.Add(jetski);
            watercrafts.Add(boat);

            // With a single `foreach`, have each water vehicle Drive()
            foreach (var watercraft in watercrafts)
            {
                watercraft.Driving(5);
            }

            Console.ReadKey();
        }
Ejemplo n.º 10
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        List <IAir> aircrafts = new List <IAir>();
        C5          galaxy    = new C5();

        aircrafts.Add(galaxy);
        Cessna bird = new Cessna();

        aircrafts.Add(bird);
        Boieng747 southwest = new Boieng747();

        aircrafts.Add(southwest);
        // With a single `foreach`, have each vehicle Fly()
        foreach (var air in aircrafts)
        {
            air.Fly();
        }

        // Build a collection of all vehicles that operate on roads
        List <ILand> rovers     = new List <ILand>();
        Motorcycle   motorcycle = new Motorcycle();
        StationWagon leBaron    = new StationWagon();
        Lancer       lancer     = new Lancer();

        rovers.Add(motorcycle);
        rovers.Add(leBaron);
        rovers.Add(lancer);
        // With a single `foreach`, have each road vehicle Drive()
        foreach (var rover in rovers)
        {
            rover.Drive();
        }

        // Build a collection of all vehicles that operate on water
        List <IWater> floats   = new List <IWater>();
        JetSki        yamaha   = new JetSki();
        Speedboat     smuggler = new Speedboat();
        Yacht         money    = new Yacht();

        floats.Add(yamaha);
        floats.Add(smuggler);
        floats.Add(money);
        // With a single `foreach`, have each water vehicle Drive()
        foreach (var floaties in floats)
        {
            floaties.Drive();
        }
    }
Ejemplo n.º 11
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        List <IAirVehicle> thingsThatFly = new List <IAirVehicle>();
        Cessna             plane         = new Cessna();
        Propplane          pesticide     = new Propplane();

        thingsThatFly.Add(plane);
        thingsThatFly.Add(pesticide);

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


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

        List <ILandVehicle> thingsThatDrive = new List <ILandVehicle>();
        Motorcycle          bike            = new Motorcycle();
        Ferrari             coolCar         = new Ferrari();

        thingsThatDrive.Add(bike);
        thingsThatDrive.Add(coolCar);

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


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

        List <IWaterVehicle> thingsThatSwim = new List <IWaterVehicle>();
        JetSki    ski           = new JetSki();
        SpeedBoat midlifeCrisis = new SpeedBoat();

        thingsThatSwim.Add(ski);
        thingsThatSwim.Add(midlifeCrisis);

        // With a single `foreach`, have each water vehicle Drive()
        foreach (IWaterVehicle swim in thingsThatSwim)
        {
            swim.Drive();
        }
    }
Ejemplo n.º 12
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        Cessna newCessna = new Cessna();
        Boeing newBoeing = new Boeing();

        List <IAir> airVehicles = new List <IAir>();

        airVehicles.Add(newCessna);
        airVehicles.Add(newBoeing);

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

        // Build a collection of all vehicles that operate on roads
        Motorcycle newCycle = new Motorcycle();
        BMW        newBmw   = new BMW();

        List <IGround> groundVehicles = new List <IGround>();

        groundVehicles.Add(newCycle);
        groundVehicles.Add(newBmw);

        // With a single `foreach`, have each road vehicle Drive()
        foreach (var vehicle in groundVehicles)
        {
            vehicle.Drive();
        }

        // Build a collection of all vehicles that operate on water
        JetSki newJetski = new JetSki();
        Yacht  newYacht  = new Yacht();

        List <IWater> waterVehicles = new List <IWater>();

        waterVehicles.Add(newJetski);
        waterVehicles.Add(newYacht);

        // With a single `foreach`, have each water vehicle Drive()
        foreach (var vehicle in waterVehicles)
        {
            vehicle.Drive();
        }
    }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            var cessna = new Cessna();
            var ufo    = new UFO();

            var delorean = new DeLorean();
            var ducati   = new Ducati();

            var jetski  = new JetSki();
            var tugboat = new Tugboat();


            // Build a collection of all vehicles that fly
            var flyingStuff = new List <IFly> {
                cessna, ufo
            };

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


            // Build a collection of all vehicles that operate on roads
            var roadRunners = new List <IDriver> {
                delorean, ducati
            };

            // With a single `foreach`, have each road vehicle Drive()
            foreach (var roadHog in roadRunners)
            {
                roadHog.Drive();
            }


            // Build a collection of all vehicles that operate on water
            var waveracers = new List <ISwimmer> {
                jetski, tugboat
            };

            // With a single `foreach`, have each water vehicle Drive()
            foreach (var boat in waveracers)
            {
                boat.Drive();
            }
        }
Ejemplo n.º 14
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        CessiPoo cesiOneKenobi = new CessiPoo();
        Cessna   plainCesna    = new Cessna();

        List <IFly> flyList = new List <IFly>()
        {
            cesiOneKenobi, plainCesna
        };

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

        foreach (IFly item in flyList)
        {
            item.Fly();
        }

        // Build a collection of all vehicles that operate on roads
        Motorcycle CrotchRocket    = new Motorcycle();
        Moped      SomeKindOfMoped = new Moped();

        // With a single `foreach`, have each road vehicle Drive()
        List <ILand> landList = new List <ILand>()
        {
            CrotchRocket, SomeKindOfMoped
        };

        foreach (ILand item in landList)
        {
            item.Drive();
        }
        // Build a collection of all vehicles that operate on water
        JetSki   imAwesome       = new JetSki();
        SailBoat superSailorMoon = new SailBoat();

        List <IWater> waterList = new List <IWater>()
        {
            imAwesome, superSailorMoon
        };

        // With a single `foreach`, have each water vehicle Drive()
        foreach (IWater item in waterList)
        {
            item.Drive();
        }
    }
Ejemplo n.º 15
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        Cessna     aCessna     = new Cessna();
        FighterJet aFighterJet = new FighterJet();

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

        Flyers.Add(aCessna);
        Flyers.Add(aFighterJet);
        // With a single `foreach`, have each vehicle Fly()
        foreach (var air in Flyers)
        {
            air.Fly();
        }

        // Build a collection of all vehicles that operate on roads
        GoKart     aGoKart     = new GoKart();
        Motorcycle aMotorcycle = new Motorcycle();

        List <IDriver> Drivers = new List <IDriver>();

        Drivers.Add(aGoKart);
        Drivers.Add(aMotorcycle);

        // With a single `foreach`, have each road vehicle Drive()
        foreach (var road in Drivers)
        {
            road.Drive();
        }

        // Build a collection of all vehicles that operate on water
        Oceanliner anOceanliner = new Oceanliner();
        JetSki     aJetSki      = new JetSki();

        List <IWater> Boats = new List <IWater>();

        Boats.Add(anOceanliner);
        Boats.Add(aJetSki);

        // With a single `foreach`, have each water vehicle Drive()
        foreach (var water in Boats)
        {
            water.Drive();
        }
    }
Ejemplo n.º 16
0
    public static void Main()
    {
        // Build a collection of all vehicles that fly
        Cessna         dylan  = new Cessna();
        Helicopter     cat    = new Helicopter();
        List <IFlying> flying = new List <IFlying>();

        flying.Add(dylan);
        flying.Add(cat);
        // With a single `foreach`, have each vehicle Fly()
        foreach (var thing in flying)
        {
            thing.Fly();
        }
        ;


        // Build a collection of all vehicles that operate on roads
        Motorcycle      heidi    = new Motorcycle();
        Car             spradlin = new Car();
        List <IDriving> driving  = new List <IDriving>();

        driving.Add(heidi);
        driving.Add(spradlin);
        // With a single `foreach`, have each road vehicle Drive()
        foreach (var thing2 in driving)
        {
            thing2.Drive();
        }
        ;


        // Build a collection of all vehicles that operate on water
        JetSki           edward  = new JetSki();
        Yacht            jerry   = new Yacht();
        List <IMaritime> sailing = new List <IMaritime>();

        sailing.Add(edward);
        sailing.Add(jerry);
        // With a single `foreach`, have each water vehicle Drive()
        foreach (var thing3 in sailing)
        {
            thing3.Drive();
        }
        ;
    }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            var jetski     = new JetSki();
            var houseboat  = new Houseboat();
            var a10warthog = new a10Warthog();
            var cessna     = new Cessna();
            var motorcycle = new Motorcycle();
            var batmobile  = new Batmobile();

            var landvehicles = new List <LandBased> {
                motorcycle, batmobile
            };

            foreach (var type in landvehicles)
            {
                type.Drive();
            }

            var airvehicles = new List <AirBased> {
                a10warthog, cessna
            };

            foreach (var type in airvehicles)
            {
                type.Fly();
            }

            var seavehicles = new List <SeaBased> {
                jetski, houseboat
            };

            foreach (var type in seavehicles)
            {
                type.Drive();
            }

            Console.ReadLine();
        }
Ejemplo n.º 18
0
        public static void Main(string[] args)
        {
            var jetski      = new JetSki();
            var waterCraft1 = new WaterCraft(jetski);

            waterCraft1.Move();
            waterCraft1.Start();
            waterCraft1.Stop();

            Console.WriteLine("------------------------------------------------");

            var submarine   = new SubMarine();
            var waterCraft2 = new WaterCraft(submarine);

            waterCraft2.Move();
            waterCraft2.Start();
            waterCraft2.Stop();

            Console.WriteLine("------------------------------------------------");

            var cessna    = new Cessna();
            var airCraft1 = new AirCraft(cessna);

            airCraft1.Move();
            airCraft1.Start();
            airCraft1.Stop();

            Console.WriteLine("------------------------------------------------");

            var airplane  = new Airplane();
            var airCraft2 = new AirCraft(airplane);

            airCraft2.Move();
            airCraft2.Start();
            airCraft2.Stop();

            Console.WriteLine("------------------------------------------------");

            var motorcycle = new Motorcycle();
            var landCraft1 = new LandCraft(motorcycle);

            landCraft1.Move();
            landCraft1.Start();
            landCraft1.Stop();

            Console.WriteLine("------------------------------------------------");

            var bike       = new Bike();
            var landCraft2 = new LandCraft(bike);

            landCraft2.Move();
            landCraft2.Start();
            landCraft2.Stop();

            Console.WriteLine("------------------------------------------------");

            // Build a collection of all vehicles that fly

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

            var airCrafts = new List <AirCraft>()
            {
                airCraft1, airCraft2
            };

            foreach (var airCraft in airCrafts)
            {
                airCraft.Move();
            }

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

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

            var landCrafts = new List <LandCraft>()
            {
                landCraft1, landCraft2
            };

            foreach (var landCraft in landCrafts)
            {
                landCraft.Move();
            }

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

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


            var waterCrafts = new List <WaterCraft>()
            {
                waterCraft1, waterCraft2
            };

            foreach (var waterCraft in waterCrafts)
            {
                waterCraft.Move();
            }
        }
Ejemplo n.º 19
0
    public static void Main()
    {
        // create some vehicles using the vehicle classes
        JetSki              StriperJetSki     = new JetSki();
        Motorboat           LargeMotorboat    = new Motorboat(12);
        Motorboat           FastMotorboat     = new Motorboat(8, 6.1);
        Sailboat            LumberingSailBoat = new Sailboat();
        Motorcycle          ZippyMotorcycle   = new Motorcycle();
        SportsCar           LeMansSportsCar   = new SportsCar();
        SportUtilityVehicle Rover             = new SportUtilityVehicle();
        Cessna              TravelingCessna   = new Cessna();
        Boeing747           AirFrance         = new Boeing747();
        HangGlider          SeeingBrazil      = new HangGlider();


        // Build a collection of all vehicles that fly
        List <IVehicleAir> flyingVehicles = new List <IVehicleAir>()
        {
            TravelingCessna,
            AirFrance,
            SeeingBrazil
        };

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


        // Build a collection of all vehicles that operate on roads
        List <IVehicleLand> landVehicles = new List <IVehicleLand>()
        {
            ZippyMotorcycle,
            LeMansSportsCar,
            Rover
        };

        // With a single `foreach`, have each road vehicle Drive()
        foreach (IVehicleLand vehicle in landVehicles)
        {
            vehicle.Drive();
        }


        // Build a collection of all vehicles that operate on water
        List <IWaterDrive> waterVehicles = new List <IWaterDrive>()
        {
            StriperJetSki,
            LumberingSailBoat,
            LargeMotorboat,
            FastMotorboat
        };

        // With a single `foreach`, have each water vehicle Drive()
        foreach (IWaterDrive vehicle in waterVehicles)
        {
            vehicle.Drive();
        }

        // check to see if my overloaded constructor functions for the Motorboat class work
        Console.WriteLine($"LargeMotorboat passenger capacity: {LargeMotorboat.PassengerCapacity}");
        Console.WriteLine($"FastMotorboat Passenger Capacity: {FastMotorboat.PassengerCapacity} Engine Volume: {FastMotorboat.EngineVolume}");
    }