Example #1
0
        static void Main(string[] args)

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

            List <IElectric> electricVehicles = new List <IElectric> {
                fx, fxs, modelS
            };

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

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

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

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

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

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

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

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

            foreach (IPetrol gv in gasVehicles)
            {
                Console.WriteLine($"{gv.CurrentTankPercentage}");
            }
        }
        static void Main(string[] args)
        {
            //Create new cars
            Zero Moto = new Zero()
            {
                BatteryKWh              = 2000,
                MainColor               = "white",
                MaximumOccupancy        = "2",
                CurrentChargePercentage = 89
            };

            Cessna Ces = new Cessna()
            {
                FuelCapacity          = 3600,
                MainColor             = "gray",
                MaximumOccupancy      = "10",
                CurrentTankPercentage = 40
            };

            Tesla Tes = new Tesla()
            {
                BatteryKWh              = 2300,
                MainColor               = "black",
                MaximumOccupancy        = "4",
                CurrentChargePercentage = 23
            };

            Ram Ra = new Ram()
            {
                FuelCapacity          = 340,
                MainColor             = "sky blue",
                MaximumOccupancy      = "5",
                CurrentTankPercentage = 60
            };

            List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>()
            {
                Moto, Tes
            };

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

            foreach (IElectricVehicle ev in electricVehicles)
            {
                ev.ChargeBattery();
            }

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

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

            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}%");
            }
            Console.WriteLine("");

            //Call method on all cars
            Ces.Drive();
            Ces.Turn("left");
            Ces.Stop();
            Console.WriteLine("");

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

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

            Moto.Drive();
            Moto.Turn("right");
            Moto.Stop();
            Console.WriteLine("");
        }
Example #3
0
        static void Main(string[] args)
        {
            Zero fxs = new Zero();

            fxs.CurrentChargePercentage = 99;
            Zero fx = new Zero();

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

            modelS.CurrentChargePercentage = 75;

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

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

            foreach (IElectric ev in electricVehicles)
            {
                // This should charge the vehicle to 100%
                ev.ChargeBattery();
                Console.WriteLine($"*C H A R G I N G*");
            }

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

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

            Ram ram = new Ram();

            ram.CurrentTankPercentage = 34;
            Cessna cessna150 = new Cessna();

            cessna150.CurrentTankPercentage = 65;

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

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

            foreach (IGas gv in gasVehicles)
            {
                // This should completely refuel the gas tank
                gv.RefuelTank();
                Console.WriteLine("*R E F U E L I N G*");
            }

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