Пример #1
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("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();
            Cessna cessna150 = new Cessna();

            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}");
            }
        }
Пример #2
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);
            // modelS.ChargeBattery();


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

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

            gasVehicles.ForEach(gv => gv.RefuelTank());
        }