Practice Exercises C# Sharp - Learn to program with performing exercises C# Sharp

Practice Exercises C# Sharp

Learn to program with performing exercises C# Sharp

Vehicles - Practice Exercises C# Sharp
Practice Exercises C# Sharp4,85320940

Vehicles - Practice Exercises C# Sharp


Lesson 6:

Object oriented programming


Exercise 6.4:

Vehicles


Objetive:

Using Visual Studio, create a project and the corresponding classes (using several files) for this classes diagram. Each class must include the attributes and methods shown in the diagram, as well as Get and Set methods for Vehicle and "Has" methods ("HasDualSlidingDoors") for MiniVan.

You must create also a test program, which will create an object belonging to each class and tell it to "Drive".


Source Code:


using System;
namespace Vehicles
{
    class Car : Vehicle
    {

    }
}

using System;
namespace Vehicles
{
    class ExcursionVan : Van
    {
    }
}

using System;
namespace Vehicles
{
    class Minivan : Van
    {
        protected bool cargo_Net;
        protected bool dual_Sliding_Doors;

        public Minivan()
        {
        }
        public Minivan(bool cargo_Net, bool dual_Sliding_Doors)
        {
            this.cargo_Net = cargo_Net;
            this.dual_Sliding_Doors = dual_Sliding_Doors;
        }

        public void SetCargoNet(bool cargo_Net)
        {
            this.cargo_Net = cargo_Net;
        }
        public void SetDualSlidingDoors(bool dual_Sliding_Doors)
        {
            this.dual_Sliding_Doors = dual_Sliding_Doors;
        }

        public bool HasCargoNet()
        {
            return cargo_Net;
        }
        public bool HasDualSlidingDoors()
        {
            return dual_Sliding_Doors;
        }
    }
}

using System;
namespace Vehicles
{
    class Sportscar : Car
    {

    }
}

using System;
namespace Vehicles
{
    class TestVehicles
    {
        static void Main()
        {
            Car myCar = new Car();
            myCar.Drive();

            Sportscar mySportsCar = new Sportscar();
            mySportsCar.Drive();

            Van myVan = new Van();
            myVan.Drive();

            Minivan myMiniVan = new Minivan();
            myMiniVan.Drive();

            ExcursionVan myExcursionVan = new ExcursionVan();
            myExcursionVan.Drive();
        }
    }
}

using System;
namespace Vehicles
{
    class Van : Vehicle
    {

    }
}

using System;
namespace Vehicles
{
    class Vehicle
    {
        protected string make;
        protected string model;
        protected string year;

        public Vehicle()
        {
        }
        public Vehicle(string make, string model, string year)
        {
            this.make = make;
            this.model = model;
            this.year = year;
        }

        public string Make
        {
            set { make = value; }
            get { return make; }
        }
        public string Model
        {
            set { model = value; }
            get { return model; }
        }
        public string Year
        {
            set { year = value; }
            get { return year; }
        }

        public void Accelerate()
        {
        }
        public void Decelerate()
        {
        }
        public void Drive()
        {
        }
        public void Start()
        {
        }
        public void Stop()
        {
        }
    }
}
Exercisey 6.4

Share Now:







Privacy Policy:



Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.

Cookies

This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.