示例#1
0
        static void Main(string[] args)
        {
            Zero   fxs   = new Zero();
            Tesla  tesla = new Tesla();
            Cessna mx410 = new Cessna();
            Ram    ram   = new Ram();

            System.Console.WriteLine("..........");
            fxs.Drive();
            fxs.Direction("squeals around right turn");
            fxs.Stop();

            System.Console.WriteLine("..........");
            tesla.Drive();
            tesla.Direction("carefully");
            tesla.Stop();

            System.Console.WriteLine("..........");
            mx410.Drive();
            mx410.Direction("not smoothly");
            mx410.Stop();

            System.Console.WriteLine("..........");
            ram.Drive();
            ram.Direction("widely");
            ram.Stop();
        }
示例#2
0
        static void Main(string[] args)
        {
            Zero  fxs    = new Zero();
            Zero  fx     = new Zero();
            Tesla modelS = new Tesla();

            List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>()
            {
                fx, fxs, modelS
            };

            Console.WriteLine("------------------------");
            Console.WriteLine("Electric Vehicles");
            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"The Vehivle is {ev.CurrentChargePercentage}% charged");
            }

            foreach (IElectricVehicle ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
            }

            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"The vehicle is now {ev.CurrentChargePercentage}% charged!");
            }

            /***********************************************/

            Ram    ram       = new Ram();
            Cessna cessna150 = new Cessna();

            List <IGasVehicle> gasVehicles = new List <IGasVehicle>()
            {
                ram, cessna150
            };

            Console.WriteLine("------------------------");
            Console.WriteLine("Gas Vehicles");
            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"The tank is {gv.CurrentTankPercentage}% full");
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"The tank is now {gv.CurrentTankPercentage}% full!");
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            Zero  fxs    = new Zero();
            Zero  fx     = new Zero();
            Tesla modelS = new Tesla();

            List <ICharging> electricVehicles = new List <ICharging>()
            {
                fx, fxs, modelS
            };

            Console.WriteLine("Electric Vehicles");
            // foreach (ICharging ev in electricVehicles)
            // {
            //     Console.WriteLine($"{ev.CurrentChargePercentage}");
            // }

            foreach (ICharging ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
            }

            // foreach (ICharging ev in electricVehicles)
            // {
            //     Console.WriteLine($"{ev.CurrentChargePercentage}");
            // }

            /***********************************************/

            Ram    ram       = new Ram();
            Cessna cessna150 = new Cessna();

            List <IGassinUp> gasVehicles = new List <IGassinUp>()
            {
                ram, cessna150
            };

            Console.WriteLine("Gas Vehicles");
            // foreach (IGassinUp gv in gasVehicles)
            // {
            //     Console.WriteLine($"{gv.CurrentTankPercentage}");
            // }

            foreach (IGassinUp gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
            }

            // foreach (IGassinUp gv in gasVehicles)
            // {
            //     Console.WriteLine($"{gv.CurrentTankPercentage}");
            // }
        }
示例#4
0
        static void Main(string[] args)
        {
            /*
             *  Create some electric vehicles, add them to a List
             *  and then iterate the List to charge all of their
             *  batteries.
             */

            Zero  fxs    = new Zero();
            Zero  fx     = new Zero();
            Tesla modelS = new Tesla();

            // List<IElectricPowered> electricVehicles = new List<IElectricPowered>()
            // {
            //     fx,
            //     fxs,
            //     modelS
            // };

            /*
             *  This can only hold individual motorcycles. You can't
             *  add the Tesla to this list. It's a different type.
             *  This is invalid code. The `modelS` is not of type Zero.
             */

            // this is the old code that wont allow separate classes in one list
            // List<Zero> electricVehicles = new List<Zero>() { fx, fxs, modelS };

            List <IElectricPowered> electricVehicles = new List <IElectricPowered>();

            electricVehicles.Add(fx);
            electricVehicles.Add(fxs);
            electricVehicles.Add(modelS);

            Console.WriteLine($" {electricVehicles}");

            electricVehicles.ForEach(ev => ev.ChargeBattery());

            /*
             *  Create some gas vehicles, add them to a List
             *  and then iterate the List to fill all of their
             *  fuel tanks.
             */
            Ram    ram       = new Ram();
            Cessna cessna150 = new Cessna();

            List <IGasPowered> gasVehicles = new List <IGasPowered>();

            gasVehicles.Add(ram);
            gasVehicles.Add(cessna150);
            // ram,
            // cessna150

            gasVehicles.ForEach(gv => gv.RefuelTank());
        }
示例#5
0
        static void Main(string[] args)
        {
            // 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()

            Cessna     blueCessna    = new Cessna();
            Motorcycle redMotorcycle = new Motorcycle();
            JetSki     pinkJetski    = new JetSki();

            List <IAirVehicle> airVehicles = new List <IAirVehicle>()
            {
                blueCessna
            };
            List <ILandVehicle> landVehicles = new List <ILandVehicle>()
            {
                redMotorcycle
            };
            List <IWaterVehicle> waterVehicles = new List <IWaterVehicle>()
            {
                pinkJetski
            };

            foreach (IWaterVehicle waterVehicle in waterVehicles)
            {
                waterVehicle.Drive();
            }
            foreach (IAirVehicle airVehicle in airVehicles)
            {
                airVehicle.Fly();
            }
            foreach (ILandVehicle landVehicle in landVehicles)
            {
                landVehicle.Drive();
            }
        }
示例#6
0
        public static void Main()
        {
            Cessna fxs  = new Cessna();
            Piper  b540 = new Piper();

            // Build a collection of all vehicles that fly
            List <IFly> planes = new List <IFly>()
            {
                fxs, b540
            };

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

            Motorcycle honda = new Motorcycle();
            Slingshot  slr   = new Slingshot();
            // Build a collection of all vehicles that operate on roads
            List <IDrive> bikes = new List <IDrive>()
            {
                honda, slr
            };

            // With a single `foreach`, have each road vehicle Drive()
            foreach (IDrive bike in bikes)
            {
                bike.Drive();
            }

            JetSki    kawasaki = new JetSki();
            Catamaran catana   = new Catamaran();
            // Build a collection of all vehicles that operate on water
            List <IAmphibious> boats = new List <IAmphibious>()
            {
                kawasaki, catana
            };

            // With a single `foreach`, have each water vehicle Drive()
            foreach (IAmphibious boat in boats)
            {
                boat.Drive();
            }
        }
示例#7
0
        public static void Main()
        {
            Cessna     plane    = new Cessna();
            Blimp      blimpy   = new Blimp();
            Motorcycle bike     = new Motorcycle();
            Truck      bigtruck = new Truck();
            JetSki     zippy    = new JetSki();
            SpeedBoat  speedy   = new SpeedBoat();

            // Build a collection of all vehicles that fly

            List <IAir> FlyingVehicles = new List <IAir>()
            {
                plane, blimpy
            };

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

            FlyingVehicles.ForEach(v => v.Fly());


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

            List <ILand> LandVehicles = new List <ILand>()
            {
                bike, bigtruck
            };

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

            LandVehicles.ForEach(v => v.Drive());


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

            List <IWater> WaterVehicles = new List <IWater>()
            {
                zippy, speedy
            };

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

            WaterVehicles.ForEach(v => v.Drive());
        }
示例#8
0
        static void Main(string[] args)
        {
            Zero  fxs    = new Zero();
            Zero  fx     = new Zero();
            Tesla modelS = new Tesla();
            List <IElectricPowered> electricVehicles = new List <IElectricPowered>();

            electricVehicles.Add(fx);
            electricVehicles.Add(fxs);
            electricVehicles.Add(modelS);

            Ram                ram         = new Ram();
            Cessna             cessna150   = new Cessna();
            List <IGasPowered> gasVehicles = new List <IGasPowered>()
            {
                ram, cessna150
            };

            gasVehicles.ForEach(gv => gv.RefuelTank());
            electricVehicles.ForEach(ev => ev.ChargeBattery());
        }
        public static void Main()
        {
            Cessna     plane           = new Cessna();
            Car        Accord          = new Car();
            FighterJet Jet             = new FighterJet();
            JetSki     Floaty          = new JetSki();
            Motorcycle AndreBikey      = new Motorcycle();
            Boat       BoatyMcBoatFace = new Boat();

            // Build a collection of all vehicles that fly
            List <IAir> FlyingThings = new List <IAir>()
            {
                plane, Jet
            };

            // With a single `foreach`, have each vehicle Fly()
            FlyingThings.ForEach(ft => ft.Fly());



            // Build a collection of all vehicles that operate on roads
            List <ILand> RoadVehicles = new List <ILand>()
            {
                AndreBikey, Accord
            };

            // With a single `foreach`, have each road vehicle Drive()
            RoadVehicles.ForEach(rv => rv.Drive());



            // Build a collection of all vehicles that operate on water
            List <IWater> WaterVehicles = new List <IWater>()
            {
                BoatyMcBoatFace, Floaty
            };

            // With a single `foreach`, have each water vehicle Drive()
            WaterVehicles.ForEach(wv => wv.Drive());
        }
示例#10
0
        static void Main(string[] args)
        {
            Boeing boeing = new Boeing();
            Cessna cessna = new Cessna();

            // Build a collection of all vehicles that fly
            List <IFlyingVehicle> flyingVehicles = new List <IFlyingVehicle>()
            {
                boeing,
                cessna
            };

            // With a single `foreach`, have each vehicle Fly()
            flyingVehicles.ForEach(vehicle => vehicle.Fly());


            HouseBoat houseboat = new HouseBoat();
            JetSki    jetski    = new JetSki();
            // Build a collection of all vehicles that operate on water
            List <ISwimmingVehicle> swimmingVehicles = new List <ISwimmingVehicle>()
            {
                houseboat,
                jetski
            };

            // With a single `foreach`, have each water vehicle Drive()
            swimmingVehicles.ForEach(vehicle => vehicle.Drive());

            Motorcycle motorcycle = new Motorcycle();
            RAV4       rav4       = new RAV4();
            // Build a collection of all vehicles that operate on roads
            List <IDrivingVehicle> drivingVehicles = new List <IDrivingVehicle>()
            {
                motorcycle,
                rav4
            };

            // With a single `foreach`, have each road vehicle Drive()
            drivingVehicles.ForEach(vehicle => vehicle.Drive());
        }
示例#11
0
        static void Main(string[] args)
        {
            Zero   fxs      = new Zero();
            Tesla  modelS   = new Tesla();
            Cessna mx410    = new Cessna();
            Ram    bigTruck = new Ram();

            fxs.MainColor        = "red";
            fxs.MaximumOccupancy = "4";

            modelS.MainColor        = "grey";
            modelS.MaximumOccupancy = "5";

            mx410.MainColor        = "white";
            mx410.MaximumOccupancy = "2";

            bigTruck.MainColor        = "blue";
            bigTruck.MaximumOccupancy = "3";

            fxs.Drive();
            fxs.Turn("right");
            fxs.Stop();
            Console.WriteLine(" ");

            modelS.Drive();
            modelS.Turn("left");
            modelS.Stop();
            Console.WriteLine(" ");

            mx410.Drive();
            mx410.Turn("right");
            mx410.Stop();
            Console.WriteLine(" ");

            bigTruck.Drive();
            bigTruck.Turn("left");
            bigTruck.Stop();
            Console.WriteLine(" ");
        }
示例#12
0
        public static void Main()
        {
            Cessna     M1     = new Cessna();
            Cessna     M2     = new Cessna();
            Motorcycle Harley = new Motorcycle();
            JetSki     JetSki = new JetSki();

            // Build a collection of all vehicles that fly
            List <IFlyingVehicle> Flying = new List <IFlyingVehicle>();

            Flying.Add(M1);
            Flying.Add(M2);
            // With a single `foreach`, have each vehicle Fly()
            foreach (IFlyingVehicle plane in Flying)
            {
                plane.Fly();
            }
            // Build a collection of all vehicles that operate on roads
            List <ILandVehichle> Driving = new List <ILandVehichle>();

            Driving.Add(Harley);
            // With a single `foreach`, have each road vehicle Drive()
            foreach (ILandVehichle car in Driving)
            {
                car.Drive();
            }


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

            Boating.Add(JetSki);
            // With a single `foreach`, have each water vehicle Drive()
            foreach (IWaterVehicle boat in Boating)
            {
                boat.Drive();
            }
        }
示例#13
0
        static void Main(string[] args)
        {
            Zero fxs = new Zero()
            {
                MainColor = "Midnight Blue",
                CurrentChargePercentage = 50
            };

            Tesla modelS = new Tesla()
            {
                MainColor = "Burgundy",
                CurrentChargePercentage = 20
            };

            Cessna mx410 = new Cessna()
            {
                MainColor             = "White",
                CurrentTankPercentage = 22
            };

            Ram truck = new Ram()
            {
                MainColor             = "Silver",
                CurrentTankPercentage = 12
            };

            List <Vehicle> allVehicles = new List <Vehicle>()
            {
                fxs,
                modelS,
                truck,
                mx410
            };

            allVehicles.ForEach(vehicle =>
            {
                vehicle.Drive();
                vehicle.Turn("right");
                vehicle.Stop();
                Console.WriteLine();
            });

            List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>()
            {
                fxs,
                modelS
            };

            Console.WriteLine("Electric Vehicles:");
            electricVehicles.ForEach(ev =>
            {
                Console.WriteLine($"{ev.CurrentChargePercentage}");
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
                Console.WriteLine($"{ev.CurrentChargePercentage}");
                Console.WriteLine();
            });

            List <IGasVehicle> gasVehicles = new List <IGasVehicle>()
            {
                truck,
                mx410
            };

            Console.WriteLine("Gas Vehicles:");
            gasVehicles.ForEach(gv =>
            {
                Console.WriteLine($"{gv.CurrentTankPercentage}");
                // This should completely refuel the gas tank
                gv.RefuelTank();
                Console.WriteLine($"{gv.CurrentTankPercentage}");
                Console.WriteLine();
            });
        }
示例#14
0
        static void Main(string[] args)
        {
            /* INHERITANCE */

            Zero fxs = new Zero()
            {
                MainColor = "Red"
            };

            Tesla modelS = new Tesla()
            {
                MainColor = "Black"
            };

            Cessna mx410 = new Cessna()
            {
                MainColor = "White"
            };

            Ram fifteenHundred = new Ram()
            {
                MainColor = "Blue"
            };

            fxs.Drive();
            fxs.Turn("left");
            fxs.Stop();

            modelS.Drive();
            modelS.Turn("left");
            modelS.Stop();

            mx410.Drive();
            mx410.Turn("right");
            mx410.Stop();

            fifteenHundred.Drive();
            fifteenHundred.Turn("right");
            fifteenHundred.Stop();

            /***********************************************/

            /* INTERFACE */

            Zero sr = new Zero()
            {
                CurrentChargePercentage = "67%"
            };
            Zero ds = new Zero()
            {
                CurrentChargePercentage = "42%"
            };
            Tesla modelX = new Tesla()
            {
                CurrentChargePercentage = "86%"
            };

            List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>()
            {
                sr,
                ds,
                modelX
            };

            Console.WriteLine("Electric Vehicles");
            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage}");
            }

            foreach (IElectricVehicle ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
            }

            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage}");
            }

            /***********************************************/

            Ram ram = new Ram()
            {
                CurrentTankPercentage = "32%"
            };
            Cessna cessna150 = new Cessna()
            {
                CurrentTankPercentage = "50%"
            };

            List <IGasVehicle> gasVehicles = new List <IGasVehicle>()
            {
                ram,
                cessna150
            };

            Console.WriteLine("Gas Vehicles");
            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage}");
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage}");
            }
        }
        static void Main(string[] args)
        {
            // Electric Powered Rides
            Zero  fx     = new Zero();
            Tesla modelS = new Tesla();

            // List of electric vehicles
            List <ElectricVehicle> electricVehicles = new List <ElectricVehicle>()
            {
                fx, modelS
            };

            electricVehicles.ForEach(ev => ev.ChargeBattery());


            // Gas Powered Rides
            //(fuelCap, gasLev)
            Cessna myCessna = new Cessna(120, 50);
            Ram    myRam    = new Ram(10, 3);

            Console.WriteLine($"The Ram is entering the fueling station with {myRam.gasLevel} gallons in the tank");
            Console.WriteLine($"The Cessna is entering the fueling station {myCessna.gasLevel} gallons in the tank");


            // List of gas vehicles
            List <GasVehicle> gasVehicles = new List <GasVehicle>()
            {
                myCessna, myRam
            };


            // Battery station instance
            BatteryStation batteryStation = new BatteryStation();


            // Gas station instance and pass the new instance capacity at the gas station
            GasStation gasStation = new GasStation(3);

            // refuel all gas vehicles as the gas station if there is room. Capacity is (3)--see line 37
            if (gasStation.Refuel(gasVehicles) != null)
            {
                Console.WriteLine("Lets Fuel Em Up!");
            }
            else
            {
                Console.WriteLine("Too many vehicles, get the hell out!");
            }



            Console.WriteLine($"The Ram is leaving the fueling station with {myRam.gasLevel} gallons in the tank. Ahhh, a full tank!");
            Console.WriteLine($"The Ram is leaving the fueling station with {myCessna.gasLevel} gallons in the tank. Ahhh, a full tank!");

            // Output
            // System.Console.WriteLine("-------------");
            // myRam.Drive();
            // myRam.Turn("left");
            // myRam.Stop();
            // System.Console.WriteLine("-------------");
            // myCessna.Drive();
            // myCessna.Turn("right");
            // myCessna.Stop();
            // System.Console.WriteLine("-------------");
            // fx.Drive();
            // fx.Turn("right");
            // fx.Stop();
            // System.Console.WriteLine("-------------");
            // modelS.Drive();
            // modelS.Turn("left");
            // modelS.Stop();
            // System.Console.WriteLine("-------------");
        }
示例#16
0
        static void Main(string[] args)
        {
            Zero fxs = new Zero();
            // Tesla modelS = new Tesla();
            Cessna mx410    = new Cessna();
            Tesla  electric = new Tesla()
            {
                Name                    = "Fancy Tesla",
                BatteryKWh              = 200.00,
                MainColor               = "red",
                MaximumOccupancy        = "4",
                CurrentChargePercentage = 15.0
            };
            Cessna sedan = new Cessna()
            {
                Name                  = "Cessna Sedan",
                MainColor             = "green",
                MaximumOccupancy      = "6",
                FuelCapacity          = 18.50,
                CurrentTankPercentage = 25,
            };

            List <IElectric> electricVehicles = new List <IElectric>()
            {
                electric
            };

            Console.WriteLine("Electric Vehicles List:");
            foreach (IElectric ev in electricVehicles)
            {
                Console.WriteLine($"{ev.Name}");
                Console.WriteLine($"Battery level before charge was at {ev.CurrentChargePercentage}%");
            }

            foreach (IElectric ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
                break;
            }

            foreach (IElectric ev in electricVehicles)
            {
                Console.WriteLine($"After Charge: {ev.CurrentChargePercentage}%");
            }

            Console.WriteLine("/***********************************************/");

            // Ram ram = new Ram();
            // Cessna cessna150 = new Cessna();

            List <IGasVehicle> gasVehicles = new List <IGasVehicle>()
            {
                sedan,
            };

            Console.WriteLine("Gas Vehicles List :");
            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.Name}");
                Console.WriteLine($"Should we fill up? Tank level:{gv.CurrentTankPercentage}%");
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
                Console.WriteLine($"We got gas");
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage}");
            }
        }
        static void Main(string[] args)
        {
            Tesla car = new Tesla()
            {
                MainColor        = "black",
                MaximumOccupancy = "20",
                BatteryKWh       = 10.0
            };
            Zero motorcycle = new Zero()
            {
                MainColor        = "black",
                MaximumOccupancy = "20",
                BatteryKWh       = 15.0
            };

            List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>()
            {
                motorcycle,
                car
            };

            Console.WriteLine("Electric Vehicles");
            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage:N2}");
            }

            foreach (IElectricVehicle ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
            }

            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage:N2}");
            }

            /***********************************************/

            Cessna plane = new Cessna()
            {
                MainColor        = "blue",
                MaximumOccupancy = "6",
                FuelCapacity     = 30.0
            };
            Ram truck = new Ram()
            {
                MainColor        = "red",
                MaximumOccupancy = "20",
                FuelCapacity     = 20.0
            };

            List <IGasVehicle> gasVehicles = new List <IGasVehicle>()
            {
                truck,
                plane
            };

            Console.WriteLine("Gas Vehicles");
            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage:N2}");
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage:N2}");
            }
        }
示例#18
0
        static void Main(string[] args)
        {
            Zero fxs = new Zero()
            {
                MainColor         = "Chartreuse",
                MaximumOccupancy  = "1-2 bodies.",
                CurrentBatteryKWh = 0.70
            };
            Zero fx = new Zero()
            {
                MainColor         = "Dark Salmon",
                MaximumOccupancy  = "1-2 bodies",
                CurrentBatteryKWh = 0.80
            };
            Tesla modelS = new Tesla()
            {
                MainColor         = "Tan",
                MaximumOccupancy  = "5 bodies",
                CurrentBatteryKWh = 0.89
            };

            List <IBatteryPowered> electricVehicles = new List <IBatteryPowered>()
            {
                fx, fxs, modelS
            };

            Console.WriteLine("Electric Vehicles");
            foreach (IBatteryPowered ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage()}");
            }

            foreach (IBatteryPowered ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
            }

            Console.WriteLine("");

            foreach (IBatteryPowered ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage()}");
            }

            Console.WriteLine("");
            /***********************************************/

            Ram ram = new Ram()
            {
                MainColor        = "Cadet Blue",
                MaximumOccupancy = "3 bodies",
                CurrentFuel      = 0.40
            };
            Cessna cessna150 = new Cessna()
            {
                MainColor        = "Light Cyan",
                MaximumOccupancy = "8 bodies",
                CurrentFuel      = 0.42
            };

            List <IGasPowered> gasVehicles = new List <IGasPowered>()
            {
                ram, cessna150
            };

            Console.WriteLine("Gas Vehicles");
            foreach (IGasPowered gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage()}");
            }

            foreach (IGasPowered gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
            }

            Console.WriteLine("");

            foreach (IGasPowered gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage()}");
            }
        }
示例#19
0
        static void Main(string[] args)
        {
            //instanstiating new classes
            Zero fxs = new Zero();

            fxs.BatteryKwh = 300.00;
            fxs.CurrentChargePercentage = 20;
            Zero fx = new Zero();

            fx.BatteryKwh = 100.00;
            fx.CurrentChargePercentage = 50;
            Tesla modelS = new Tesla();

            modelS.BatteryKwh = 60;
            modelS.CurrentChargePercentage = 30;

            List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>()
            {
                fx,
                fxs,
                modelS
            };

            Console.WriteLine("Electric Vehicles");
            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage}");
            }

            //iterating through the list of electric vehicles
            foreach (IElectricVehicle ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
            }

            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"{ev.CurrentChargePercentage}");
            }

            /***********************************************/

            Ram ram = new Ram();

            ram.FuelCapacity          = 60.20;
            ram.CurrentTankPercentage = 70;
            Cessna cessna150 = new Cessna();

            cessna150.FuelCapacity          = 90.21;
            cessna150.CurrentTankPercentage = 20;

            List <IGasVehicle> gasVehicles = new List <IGasVehicle>()
            {
                ram,
                cessna150
            };

            Console.WriteLine("Gas Vehicles");
            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage}");
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
            }

            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage}");
            }
        }