0% found this document useful (0 votes)
139 views3 pages

C# Proposed Exercise4

The document instructs the creation of a vehicle class hierarchy in C# using Visual Studio. This includes base Vehicle and derived Car, Sportscar, Van, ExcursionVan, and Minivan classes. Each class must include attributes and methods as defined in a class diagram. A test program is also to be created that instantiates objects of each class and calls the "Drive" method.

Uploaded by

Paulo Pereira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views3 pages

C# Proposed Exercise4

The document instructs the creation of a vehicle class hierarchy in C# using Visual Studio. This includes base Vehicle and derived Car, Sportscar, Van, ExcursionVan, and Minivan classes. Each class must include attributes and methods as defined in a class diagram. A test program is also to be created that instantiates objects of each class and calls the "Drive" method.

Uploaded by

Paulo Pereira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C# Proposed exercise4

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".

Output

Solution

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()


{

}
}

class Car : Vehicle


{

class Sportscar : Car


{

class Van : Vehicle


{

class ExcursionVan : Van


{

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;
}
}

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();
}
}

You might also like