Exemplo n.º 1
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle-DONE
             * The vehicle class shall have three string properties Year, Make, and Model-DONE
             * Set the defaults to something generic in the Vehicle class-DONE
             * Vehicle shall have an abstract method called DriveAbstract with no implementation-DONE
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.-DONE
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle-DONE
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles-DONE
            var vehicles = new List <Vehicle>();

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax-DONE
             */

            Vehicle car1 = new Car()
            {
                Year = 2016, Make = "BMW", Model = "328i", NumberOfTires = 4, NumberOfWindows = 4
            };
            Car car2 = new Car()
            {
                Year = 1999, Make = "Dodge", Model = "Charger", NumberOfTires = 4, NumberOfWindows = 2
            };
            Motorcycle motor1 = new Motorcycle()
            {
                Year = 2019, Make = "HarleyDavidson", Model = "Sportster"
            };
            Vehicle motor2 = new Motorcycle();

            /*
             * Add the 4 vehicles to the list*/
            vehicles.Add(car1);
            vehicles.Add(car2);
            vehicles.Add(motor1);
            vehicles.Add(motor2);

            /* Using a foreach loop iterate over each of the properties
             */

            foreach (var item in vehicles)
            {
                Console.WriteLine($"{item.Year} {item.Make} {item.Model}");
                Console.WriteLine();

                // Call each of the drive methods for one car and one motorcycle
                car1.DriveAbstract();
                Console.WriteLine();
                car1.DriveVirtual();
                Console.WriteLine();
                motor1.DriveAbstract();
                motor2.DriveVirtual();
                #endregion
                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var vehicles = new List <Vehicle>();

            var ducatti = new Motorcycle();

            ducatti.Model      = "x11";
            ducatti.Year       = "2020";
            ducatti.Make       = "Duactti";
            ducatti.TopSpeed   = "201mph";
            ducatti.HasSidecar = false;

            var gWagon = new Car()
            {
                Year          = "2019",
                Model         = "G100",
                Make          = "Mercedes",
                NumberOfDoors = 4,
                TopSpeed      = "145mph"
            };

            Vehicle Indian = new Motorcycle()
            {
                Year       = "1980",
                Model      = "LightFeather",
                Make       = "Indian",
                TopSpeed   = "92mph",
                HasSidecar = false
            };

            Vehicle Outback = new Car()
            {
                NumberOfDoors = 4,
                Model         = "Outback",
                Make          = "Subaru",
                Year          = "2018",
                TopSpeed      = "113mph"
            };


            vehicles.Add(ducatti);
            vehicles.Add(gWagon);
            vehicles.Add(Indian);
            vehicles.Add(Outback);

            foreach (Vehicle v in vehicles)
            {
                Console.WriteLine($"The {v.Year} {v.Make} {v.Model}");
            }

            Indian.DriveAbstract();
            Indian.DriveVirtual();
            Outback.DriveAbstract();
            Outback.DriveVirtual();

            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            // Call each of the drive methods for one car and one motorcycle

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments in each section!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            List <Vehicle> vehicles = new List <Vehicle>();

            /*
             * Create 4 instances, 1 Car, 1 Motorcycle, and then 2 Vehicles - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            Car myCar = new Car()
            {
                Year = 2014, Make = "Buick", Model = "Encore", HasTrunk = true
            };

            Motorcycle myMotorcycle = new Motorcycle()
            {
                Year = 1958, Make = "Honda", Model = "Super Cub", HasSideCart = true
            };

            Vehicle vehicle1 = new Car()
            {
                Year = 2009, Make = "Honda", Model = "Civic", HasTrunk = true
            };

            Vehicle vehicle2 = new Motorcycle()
            {
                Year = 2009, Make = "Kawasaki", Model = "Ninja", HasSideCart = false
            };

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            vehicles.Add(myCar);
            vehicles.Add(myMotorcycle);
            vehicles.Add(vehicle1);
            vehicles.Add(vehicle2);

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine($"{vehicle.Year}, {vehicle.Make}, {vehicle.Model}");
            }

            // Call each of the drive methods for one car and one motorcycle
            Console.ReadLine();
            Console.WriteLine();

            myCar.DriveAbstract();
            myCar.DriveVirtual(myCar);

            Console.WriteLine();

            myMotorcycle.DriveAbstract();
            myMotorcycle.DriveVirtual(myMotorcycle);

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            List <Vehicle> myListOfVehicles = new List <Vehicle>();

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            var batmobile = new Car();

            batmobile.Make  = "Uhmm not sure";
            batmobile.Model = "Also drawing a blank here.";
            batmobile.Year  = "This year.";

            var robincycle = new Motorcycle();

            Vehicle mrFreezThing = new Car();

            Vehicle ridlerScooter = new Motorcycle();

            myListOfVehicles.Add(batmobile);
            myListOfVehicles.Add(robincycle);
            myListOfVehicles.Add(mrFreezThing);
            myListOfVehicles.Add(ridlerScooter);

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            foreach (var t in myListOfVehicles)
            {
                t.Make  = "WhoKnows?";
                t.Model = "I really don't konw";
                t.Year  = "Probably fairly recent";
            }

            // Call each of the drive methods for one car and one motorcycle

            batmobile.DriveAbstract();
            batmobile.DriveVirtual();
            robincycle.DriveVirtual();
            robincycle.DriveAbstract();


            #endregion
            Console.ReadLine();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var vehicles = new List <Vehicle>();

            var juansCar = new Car()
            {
                Year = 2021, Make = "Ford", Model = "Explorer"
            };
            var juansMotorcycle = new Motorcycle()
            {
                Year = 2019, Make = "Harley", Model = "Kt500"
            };
            Vehicle juanOneVehicle = new Car()
            {
                Year = 2017, Make = "Toyota", Model = "Camry"
            };
            Vehicle juanTwoVehicle = new Motorcycle()
            {
                Year = 2015, Make = "Honda", Model = "Ninja300"
            };

            vehicles.Add(juansCar);
            vehicles.Add(juansMotorcycle);
            vehicles.Add(juanOneVehicle);
            vehicles.Add(juanTwoVehicle);

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine($"My {vehicle.Model} it's mark is {vehicle.Make} and it is of {vehicle.Year}");
            }

            juansCar.DriveAbstract();
            juansCar.DriveVirtual();
            juansMotorcycle.DriveAbstract();
            juansMotorcycle.DriveVirtual();
            juanOneVehicle.DriveAbstract();
            juanOneVehicle.DriveVirtual();
            juanTwoVehicle.DriveAbstract();
            juanTwoVehicle.DriveVirtual();



            /*
             * Todo follow all comments!!
             */

            #region Vehicles



            // Create a list of Vehicle called vehicles

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            // Call each of the drive methods for one car and one motorcycle

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Complete  -  Create an abstract class called Vehicle
             * Complete  -  The vehicle class shall have three string properties Year, Make, and Model
             * Complete  -  Set the defaults to something generic in the Vehicle class
             * Complete  -  Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Complete  -  Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Complete  -  Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Complete  -  Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Complete  -  Provide the implementations for the abstract methods
             * Complete  -  Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles
            var vehicles = new List <Vehicle>();

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            Car Dodge = new Car()
            {
                HasTrunk = true, Make = "Dodge", Model = "Viper", Year = 2021
            };                                                                                       // instance of objects

            Motorcycle HarleyDavidson = new Motorcycle()
            {
                HasSideCart = false, Make = "Harley Davidson", Model = "1200", Year = 2021
            };                                                                                                                           // instance of object

            Vehicle Economy = new Car()
            {
                HasTrunk = true, Make = "Honda", Model = "Fit", Year = 2021
            };                                                                                           // instance of object

            Vehicle Luxury = new Car()
            {
                HasTrunk = true, Make = "Acura", Model = "RXL", Year = 20201
            };                                                                                           // instance of object


            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            vehicles.Add(Dodge);
            vehicles.Add(HarleyDavidson);   // Adding each object to list created "vehicles"
            vehicles.Add(Economy);
            vehicles.Add(Luxury);

            foreach (var ride in vehicles)       // for each loop to iterate through list and output properties in abstract class for each list of vehicles
            {
                Console.WriteLine($"Make:   {ride.Make}   Model:    {ride.Model}    Year:    {ride.Year}");
                Console.WriteLine("\n");
                // ride.DriveAbstract(); prints for all
                // ride.DriveVirtual(); prints for all
            }

            // Call each of the drive methods for one car and one motorcycle
            Console.WriteLine($"{Dodge.Make}    {Dodge.Model}    {Dodge.Year}");
            Dodge.DriveAbstract();
            Dodge.DriveVirtual();
            Console.WriteLine("\n");

            Console.WriteLine($"{HarleyDavidson.Make}        {HarleyDavidson.Model}            {HarleyDavidson.Year}");
            HarleyDavidson.DriveAbstract();
            HarleyDavidson.DriveVirtual();



            #endregion
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */
            #region Vehicle

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles
            List <Vehicle> vehicles = new List <Vehicle>();

            Vehicle truck = new Car()
            {
                Make = "Mercedez", Model = "Tractor", Year = 2005, HasTrunk = true
            };
            Vehicle powerBike = new Motorcycle()
            {
                Model = "Suzuki", Make = "Yamaha", Year = 2010, HasSideCart = false
            };
            Car nissan = new Car();
            nissan.Make     = "Infiniti";
            nissan.Model    = "Q-37Z";
            nissan.Year     = 2012;
            nissan.HasTrunk = true;

            Motorcycle yamaha = new Motorcycle();
            yamaha.Make        = "Yamaha";
            yamaha.Model       = "YH-09";
            yamaha.Year        = 2015;
            yamaha.HasSideCart = false;

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            vehicles.Add(truck);
            vehicles.Add(powerBike);
            vehicles.Add(nissan);
            vehicles.Add(yamaha);

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */
            foreach (var vehicle in vehicles)
            {
                Console.WriteLine($"Make: {vehicle.Make}, Model: {vehicle.Model}, Year: {vehicle.Year}");
            }

            Console.WriteLine("");
            // Call each of the drive methods for one car and one motorcycle
            truck.DriveAbstract(truck);
            truck.DriveVirtual(truck);
            Console.WriteLine("");
            yamaha.DriveAbstract(yamaha);
            yamaha.DriveVirtual(yamaha);

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles
            var vehicles = new List <Vehicle>();

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */
            Car        delorean  = new Car("1983", "DMC", "DeLorean", 2);
            Motorcycle harley    = new Motorcycle("1992", "Harley Davidson", "Junker", "Chopper");
            Vehicle    relic     = new Car();
            Vehicle    dunebuggy = new Car("2000", "Custom", "Mud Buggy", 0);

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */
            vehicles.Add(delorean);
            vehicles.Add(relic);
            vehicles.Add(dunebuggy);
            vehicles.Add(harley);

            foreach (Vehicle x in vehicles)
            {
                Console.WriteLine($"{x.Year} {x.Make} {x.Model}. \n");
            }
            // Call each of the drive methods for one car and one motorcycle

            relic.DriveVirtual(relic);
            Console.WriteLine("\n");
            delorean.DriveAbstract(delorean);
            Console.WriteLine("\n");
            harley.DriveVirtual(harley);
            Console.WriteLine("\n");
            harley.DriveAbstract(harley);

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments in each section!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            List <Vehicle> vehicles = new List <Vehicle>();

            /*
             * Create 4 instances, 1 Car, 1 Motorcycle, and then 2 Vehicles - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            Car myFirstCar = new Car()
            {
                Make          = "Cadillac",
                Model         = "SRX",
                Year          = "2014",
                HasFourWheels = true,
                HasTrunk      = true
            };
            Motorcycle myFirstBike = new Motorcycle()
            {
                Make         = "Harley Davidson",
                Model        = "Sportster",
                Year         = "2013",
                HasTwoWheels = true,
                HasSideCar   = true
            };
            Vehicle myDreamCar = new Car()
            {
                Make          = "Ford",
                Model         = "Mustang",
                Year          = "1969",
                HasFourWheels = true,
                HasTrunk      = true
            };
            Vehicle myDreamBike = new Motorcycle()
            {
                Make         = "Harley Davidson",
                Model        = "Shovel Head",
                Year         = "1984",
                HasSideCar   = true,
                HasTwoWheels = true
            };

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            vehicles.Add(myFirstCar);
            vehicles.Add(myFirstBike);
            vehicles.Add(myDreamCar);
            vehicles.Add(myDreamBike);

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine(vehicle);
            }

            // Call each of the drive methods for one car and one motorcycle

            myFirstCar.DriveAbstract();
            myFirstBike.DriveAbstract();

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles
            var vehicles = new List <Vehicle>();

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */
            Car myCar = new Car()
            {
                Year               = 2012,
                Make               = "Chevy",
                Model              = "Cruze",
                NumDoors           = 4,
                HasAirConditioning = true
            };
            Motorcycle myMotorcycle = new Motorcycle()
            {
                Year          = 2019,
                Make          = "Yamaha",
                Model         = "VMAX",
                HasSideCar    = true,
                HandlebarType = "Street"
            };
            Vehicle batmoblie = new Car()
            {
                Year  = 2000,
                Make  = "Gotham Motors",
                Model = "Batmoblie"
            };
            Vehicle racingBike = new Motorcycle()
            {
                Year  = 2020,
                Make  = "Honda",
                Model = "Fireblade"
            };
            vehicles.Add(myCar);
            vehicles.Add(myMotorcycle);
            vehicles.Add(batmoblie);
            vehicles.Add(racingBike);

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */
            foreach (Vehicle v in vehicles)
            {
                Console.WriteLine(v.Year);
                Console.WriteLine(v.Make);
                Console.WriteLine(v.Model);
            }

            // Call each of the drive methods for one car and one motorcycle
            myCar.DriveVirtual();
            myCar.DriveAbstract();
            myMotorcycle.DriveVirtual();
            myMotorcycle.DriveAbstract();

            #endregion
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            var vehicles = new List <Vehicle>();

            Car c = new Car();

            c.Name     = "Car 1";
            c.Year     = "1990";
            c.Make     = "Honda";
            c.Model    = "Civic";
            c.HasTrunk = true;

            Motorcycle m = new Motorcycle();

            m.Name       = "Motorcycle 1";
            m.Year       = "2009";
            m.Make       = "Kawasaki";
            m.Model      = "Ninja";
            m.HasSideCar = true;

            Vehicle v1 = new Car();

            v1.Name  = "Vehicle 1";
            v1.Year  = "2016";
            v1.Make  = "Nissan";
            v1.Model = "Rogue";

            Vehicle v2 = new Motorcycle();

            v2.Name  = "Vehicle 2";
            v2.Year  = "1966";
            v2.Make  = "BMW";
            v2.Model = "Bike";

            vehicles.Add(c);
            vehicles.Add(m);
            vehicles.Add(v1);
            vehicles.Add(v2);

            foreach (var item in vehicles)
            {
                Console.WriteLine($"Here are the stats on {item.Name}:");
                Console.WriteLine(item.Year);
                Console.WriteLine(item.Make);
                Console.WriteLine(item.Model);
                Console.WriteLine("");
            }

            c.DriveAbstract();
            Console.WriteLine("");
            c.DriveVirtual();
            Console.WriteLine("");
            m.DriveAbstract();
            Console.WriteLine("");
            m.DriveVirtual();


            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            // Call each of the drive methods for one car and one motorcycle

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * DONE Create an abstract class called Vehicle
             * DONE The vehicle class shall have three string properties Year, Make, and Model
             * DONE  Set the defaults to something generic in the Vehicle class
             * DONE Vehicle shall have an abstract method called DriveAbstract with no implementation
             * DONE Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             * DONE
             */

            /*
             * DONE Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * DONE Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * DONEProvide the implementations for the abstract methods
             * DONE Only in the Motorcycle class will you override the virtual drive method
             *
             */

            // Create a list of Vehicle called vehicles
            // Done

            var vehicles = new List <Vehicle>();

            /*
             * DONE Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * DONE - new it up as one of each derived class
             * DONE Set the properties with object initializer syntax
             *
             */

            Car newCar = new Car()
            {
                HasTrunk = true,
                Model    = "3285i",
                Make     = "Bmw",
                Year     = 1993
            };

            Motorcycle motorcycle = new Motorcycle()
            {
                HasSideCart = true,
                Make        = "Harley",
                Model       = "Pink",
                Year        = 1999
            };

            Vehicle sedan = new Car()
            {
                Year     = 2020,
                Model    = "Polaris",
                Make     = "GroundCrew 3s",
                HasTrunk = true
            };



            Vehicle sport = new Car()
            {
                Year     = 2003,
                Make     = "Convertible",
                Model    = "Ford Fusion",
                HasTrunk = false
            };



            /*
             * DONE Add the 4 vehicles to the list
             * DONE Using a foreach loop iterate over each of the properties
             */

            vehicles.Add(newCar);
            vehicles.Add(motorcycle);
            vehicles.Add(sedan);
            vehicles.Add(sport);

            foreach (var veh in vehicles)
            {
                Console.WriteLine($"Make {veh.Make} Model {veh.Model}  Year {veh.Year}");
                veh.DriveAbstract();
                veh.DriveVirtual();
                Console.WriteLine("----------------------------------------------");
            }


            // DONE Call each of the drive methods for one car and one motorcycle

            motorcycle.DriveAbstract();
            sport.DriveVirtual();

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles


            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing)
             * but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */


            Car mazda = new Car()
            {
                Make = "Mazda", Model = "Protege", Year = 2016
            };
            Motorcycle motor = new Motorcycle()
            {
                Make = "Suzuki", Model = "Posh", Year = 2030
            };

            Vehicle nissan = new Car();
            Vehicle honda  = new Motorcycle()
            {
                Year = 2020, Model = "Accord", Make = "Honda"
            };

            var vehicles = new List <Vehicle>();
            // List<Vehicle> vehicles1 = new List<Vehicle>();  explicit typing.
            vehicles.Add(mazda);
            vehicles.Add(nissan);
            vehicles.Add(honda);
            vehicles.Add(motor);


            foreach (var item in vehicles)
            {
                Console.WriteLine($"I have {vehicles.Count}  vehicles in my list.Which are {item.Make} {item.Model}");
            }



            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine($" {vehicle.Make } {vehicle.Model} & {vehicle.Year}");
                Console.WriteLine($" ");
            }


            // Call each of the drive methods for one car and one motorcycle


            mazda.DriveAbstract();
            mazda.DriveVirtual();

            motor.DriveAbstract();
            motor.DriveVirtual();
            #endregion
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */
            var vehicles = new List <Vehicle>();

            var myCar = new Car()
            {
                Year     = "2018",
                Make     = "Ford",
                Model    = "Focus",
                HasTrunk = true
            };

            vehicles.Add(myCar);

            var myBike = new Motorcycle()
            {
                Year        = "2011",
                Make        = "Honda",
                Model       = "Dirtbike",
                HasSideCart = false
            };

            vehicles.Add(myBike);

            Vehicle vehicle1 = new Car()
            {
                Year     = "2012",
                Make     = "Crysler",
                Model    = "PT Cruiser",
                HasTrunk = false
            };

            vehicles.Add(vehicle1);

            Vehicle vehicle2 = new Motorcycle()
            {
                Year        = "2009",
                Make        = "Harley",
                Model       = "Cross-Country",
                HasSideCart = false
            };

            vehicles.Add(vehicle2);

            Console.WriteLine("\nHere is a description of each vehicle in the list:");
            foreach (var item in vehicles)
            {
                Console.WriteLine($"{item.Year} {item.Make} {item.Model}, which is a {item.GetType()}");
            }

            Console.WriteLine("\nNow for the abstract and virtual drives for a car and motorcycle:");
            vehicle1.DriveAbstract();
            vehicle1.DriveVirtual();
            myBike.DriveAbstract();
            myBike.DriveVirtual();

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            // Call each of the drive methods for one car and one motorcycle

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * DONE Create an abstract class called Vehicle
             * DONE The vehicle class shall have three string properties Year, Make, and Model
             * DONE Set the defaults to something generic in the Vehicle class
             * DONE Vehicle shall have an abstract method called DriveAbstract with no implementation
             * DONE Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * DONE Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * DONE Add a distinct property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * DONE Provide the implementations for the abstract methods
             * DONE Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles
            var vehicles = new List <Vehicle>();

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            Car myCar = new Car()
            {
                Make = "Chevy", Model = "F150", HasTrunk = false, Year = 2014
            };


            Motorcycle myMotorcycle = new Motorcycle()
            {
                Make = "honda", Model = "CB750", Year = 1985, HasSideCart = false
            };

            Vehicle Sedan = new Car()
            {
                HasTrunk = true
            };
            Vehicle Coupe = new Car()
            {
                Make = "BMW", Year = 1972
            };

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            vehicles.Add(Sedan);
            vehicles.Add(Coupe);
            vehicles.Add(myMotorcycle);
            vehicles.Add(myCar);

            foreach (var veh in vehicles)
            {
                Console.WriteLine($"Make:{veh.Make} Model:{veh.Model} Year: {veh.Year}");
            }

            // Call each of the drive methods for one car and one motorcycle

            #endregion
            myCar.DriveVirtual();
            myMotorcycle.DriveAbstract();
            Console.ReadLine();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles
            List <Vehicle> vehicles = new List <Vehicle>();  // List<Vehicle>()  = a constructor


            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */
            Vehicle newCar = new Car()
            {
                Year = "2017", Make = "Jeep", Model = "Renegade", HasTrunk = false, HasGoodMileage = false
            };                                                                                                                         // objects
            // newCar.Year = 2017;               //     click cTRL + R+ R to change all of one filed (like all of newCar)
            //newCar.Make = "Jeep";
            //newCar.Model = "Renegade";
            //newCar.HasTrunk = true;
            //newCar.HasGoodMileage = true;

            Motorcycle newCycle = new Motorcycle();  //  Motorcycle() = a constructor  (polyphorphism - one ting many forms
            newCycle.Year          = "2019";
            newCycle.Make          = "Harley";
            newCycle.Model         = "Low Rider";
            newCycle.HasSideCart   = false;
            newCycle.HasSaddleBags = true;

            Vehicle newTruck = new Truck()
            {
                Year            = "2030",
                Make            = "Tesla",
                Model           = "Cybertruck",
                HasBallAndHitch = false
            };

            Vehicle newCopter = new Car()
            {
                Year  = "2015",
                Make  = "Gimbal",
                Model = "Dynax 5"
            };

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            vehicles.Add(newCar);
            vehicles.Add(newCycle);
            vehicles.Add(newTruck);
            vehicles.Add(newCopter);

            foreach (var veh in vehicles)
            {
                Console.WriteLine($"Year: {veh.Year}, Make: {veh.Make}, Model: {veh.Model}");
                Console.WriteLine();
            }
            // Call each of the drive methods for one car and one motorcycle, have to call the method or will not output the CW
            newCar.DriveAbstract();
            Console.WriteLine();
            newCar.DriveVirtual();
            Console.WriteLine();
            newCycle.DriveAbstract();
            Console.WriteLine();
            newCycle.DriveVirtual();
            Console.WriteLine();
            newTruck.DriveAbstract();
            Console.WriteLine();
            newTruck.DriveVirtual();
            Console.WriteLine();
            newCopter.DriveVirtual();

            #endregion
            Console.ReadLine();
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distict property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            // Call each of the drive methods for one car and one motorcycle

            #endregion

            List <Vehicle> v  = new List <Vehicle>();
            var            c1 = new Car("2020", "Toyota", "Rav4");
            var            m1 = new Motorcycle("2010", "Honda", "CB500X");
            Vehicle        c2 = new Car("2015", "Toyota", "Camery");
            Vehicle        m2 = new Motorcycle("2015", "Honda", "CB650R");

            v.Add(c1);
            v.Add(m1);
            v.Add(c2);
            v.Add(m2);

            foreach (Vehicle item in v)
            {
                Console.WriteLine($"Make: {item.Make}    Model: {item.Model}    Year: {item.Year}");
            }

            c1.DriveVirtual();
            m1.DriveVirtual();
            c1.DriveAbstract();
            m1.DriveAbstract();
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            /*
             * Create an abstract class called Vehicle
             * The vehicle class shall have three string properties Year, Make, and Model
             * Set the defaults to something generic in the Vehicle class
             * Vehicle shall have an abstract method called DriveAbstract with no implementation
             * Vehicle shall have a virtual method called DriveVirtual with a base implementation.
             */

            /*
             * Now create 2 non-abstract classes: Car and Motorcycle, that inherit from Vehicle
             * Add a distinct property in the 2 derived classes such as HasTrunk for Car and HasSideCart for Motorcycle
             * Provide the implementations for the abstract methods
             * Only in the Motorcycle class will you override the virtual drive method
             */

            // Create a list of Vehicle called vehicles

            var vehicles = new List <Vehicle>();

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle, and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */
            var car1 = new Car()
            {
                HasTrunk = true, Make = "Toyota", Model = "4Runner", NumberOfCupHolders = 12, Year = 2015
            };
            var motorcycle1 = new Motorcycle()
            {
                HasKickStand = true, Make = "Toyota", Model = "4Runner", HasSideCar = true, Year = 2015
            };
            Vehicle car2 = new Car()
            {
                HasTrunk = true, Make = "Toyota", Model = "4Runner", NumberOfCupHolders = 12, Year = 2015
            };
            Vehicle motorcycle2 = new Motorcycle()
            {
                HasKickStand = true, Make = "Toyota", Model = "4Runner", HasSideCar = false, Year = 2015
            };

            vehicles.Add(car1);
            vehicles.Add(car2);
            vehicles.Add(motorcycle1);
            vehicles.Add(motorcycle2);

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            /*
             * foreach (Car item1 in vehicles)
             * {
             *  foreach (Motorcycle item2 in vehicles)
             *  {
             *
             *      Console.WriteLine(item2.Make, item2.Model, item2.Year, item2.HasKickStand, item2.HasSideCar);
             *  }
             *  Console.WriteLine(item1.Make, item1.Model, item1.Year, item1.NumberOfCupHolders, item1.HasTrunk);
             * }
             *
             */
            foreach (var item in vehicles)
            {
                Console.WriteLine($"{item.Make}, {item.Model}, {item.Year}");
            }

            // Call each of the drive methods for one car and one motorcycle
            car1.DriveAbstract();
            car1.DriveVirtual();
            motorcycle2.DriveAbstract();
            motorcycle2.DriveVirtual();
            #endregion
            Console.ReadLine();
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            /*
             * Todo follow all comments!!
             */

            #region Vehicles

            var vehicles = new List <Vehicle>();

            var myCar = new Car();

            var myMotorcycle = new Motorcycle();

            Vehicle newCar = new Car();

            Vehicle newMoto = new Motorcycle();

            myCar.HasFourWheels = true;
            myCar.HasTrunk      = true;

            myMotorcycle.HasSideCar = false;
            myMotorcycle.IsACruiser = true;

            newCar.Make  = "Ford";
            newCar.Model = "Mustang";
            newCar.Year  = 2012;

            newMoto.DriveAbstract();


            vehicles.Add(myCar);
            vehicles.Add(myMotorcycle);
            vehicles.Add(newCar);
            vehicles.Add(newMoto);

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine(vehicle.Make);
                Console.WriteLine(vehicle.Model);
                Console.WriteLine(vehicle.Year);
                vehicle.DriveAbstract();
                vehicle.DriveVirtual();
                Console.WriteLine(" ");
                Console.WriteLine(" ");
                Console.WriteLine("********************");
            }

            // Create a list of Vehicle called vehicles

            /*
             * Create 4 instances: 1 Car, 1 Motorcycle,
             * and then 2 instances of type Vehicle (use explicit typing) but use constuctors from derived classes -Done
             * - new it up as one of each derived class
             * Set the properties with object initializer syntax
             */

            /*
             * Add the 4 vehicles to the list
             * Using a foreach loop iterate over each of the properties
             */

            // Call each of the drive methods for one car and one motorcycle

            #endregion
            Console.ReadLine();
        }