Esempio n. 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");

            electricVehicles.ForEach(v => Console.WriteLine($"{v.BatteryKWh}"));

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

            electricVehicles.ForEach(v => Console.WriteLine($"{v.BatteryKWh}"));



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

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

            Console.WriteLine("");
            Console.WriteLine("Gas Vehicles");

            gasVehicles.ForEach(v => Console.WriteLine(v.FuelCapacity));

            gasVehicles.ForEach(v => v.RefuelTank());

            gasVehicles.ForEach(v => Console.WriteLine(v.FuelCapacity));
        }
        static void Main(string[] args)
        {
            // instantiate each vehicle
            Zero myZero = new Zero()
            {
                MainColor = "smoke"
            };
            Cessna myCessna = new Cessna()
            {
                MainColor = "silver"
            };
            Tesla myTesla = new Tesla()
            {
                MainColor = "black"
            };
            Ram myRam = new Ram()
            {
                MainColor = "red"
            };

            List <IElectricVehicle> electricVehicles = new List <IElectricVehicle>()
            {
                myZero, myTesla
            };

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

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

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

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

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

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

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

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

            // myCessna.Drive();
            // myCessna.Turn("right");
            // myCessna.Stop();
            // Console.WriteLine("");


            // myTesla.Drive();
            // myTesla.Turn("left");
            // myTesla.Stop();
            // Console.WriteLine("");


            // myRam.Drive();
            // myRam.Turn("right");
            // myRam.Stop();
            // Console.WriteLine("");


            // myZero.Drive();
            // myZero.Turn("left");
            // myZero.Stop();
            // Console.WriteLine("");
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Zero   fx             = new Zero();
            Cessna oneSevenTwo    = new Cessna();
            Tesla  modelS         = new Tesla();
            Ram    fifteenHundred = new Ram();

            fx.Drive();
            fx.Turn("sharp left turn to the express lane");
            fx.Stop();
            Console.WriteLine();
            oneSevenTwo.Drive();
            oneSevenTwo.Turn("nose dive into the pacific ocean");
            oneSevenTwo.Stop();
            Console.WriteLine();
            modelS.Drive();
            modelS.Turn("U turn into the wrong side of the road");
            modelS.Stop();
            Console.WriteLine();
            fifteenHundred.Drive();
            fifteenHundred.Turn("detour to the dirt road");
            fifteenHundred.Stop();
            Console.WriteLine();

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

            Console.WriteLine("Electric Vehicles");

            // Lists current battery level for each electric vehicle
            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"Battery Level: {ev.CurrentChargePercentage}%");
            }

            // Invokes ChargeBattery() method on each electric vehicle
            foreach (IElectricVehicle ev in electricVehicles)
            {
                ev.ChargeBattery();
            }

            // Lists battery level for each electric vehicle after invoking ChargeBattery() method
            foreach (IElectricVehicle ev in electricVehicles)
            {
                Console.WriteLine($"New Battery Level: {ev.CurrentChargePercentage}%");
            }

            Console.WriteLine();

            // List of gas vehicles
            List <IGasVehicle> gasVehicles = new List <IGasVehicle>()
            {
                oneSevenTwo,
                fifteenHundred
            };

            Console.WriteLine("Gas Vehicles");

            // Lists current fuel level for each gas vehicle
            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"Current Fuel Level: {gv.CurrentTankPercentage}%");
            }

            // Invokes RefuelTank() method on each gas vehicle
            foreach (IGasVehicle gv in gasVehicles)
            {
                gv.RefuelTank();
            }

            // Lists fuel level for each gas vehicle after invoking RefuelTank() method
            foreach (IGasVehicle gv in gasVehicles)
            {
                Console.WriteLine($"New Fuel Level: {gv.CurrentTankPercentage}%");
            }
        }