Exercise
Class Vehicles
Objetive
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".
Code
Imports System
Namespace Vehicles
Class Car
Inherits Vehicle
End Class
End Namespace
Namespace Vehicles
Class ExcursionVan
Inherits Van
End Class
End Namespace
Namespace Vehicles
Class Minivan
Inherits Van
Protected cargo_Net As Boolean
Protected dual_Sliding_Doors As Boolean
Public Sub New()
End Sub
Public Sub New(ByVal cargo_Net As Boolean, ByVal dual_Sliding_Doors As Boolean)
Me.cargo_Net = cargo_Net
Me.dual_Sliding_Doors = dual_Sliding_Doors
End Sub
Public Sub SetCargoNet(ByVal cargo_Net As Boolean)
Me.cargo_Net = cargo_Net
End Sub
Public Sub SetDualSlidingDoors(ByVal dual_Sliding_Doors As Boolean)
Me.dual_Sliding_Doors = dual_Sliding_Doors
End Sub
Public Function HasCargoNet() As Boolean
Return cargo_Net
End Function
Public Function HasDualSlidingDoors() As Boolean
Return dual_Sliding_Doors
End Function
End Class
End Namespace
Namespace Vehicles
Class Sportscar
Inherits Car
End Class
End Namespace
Namespace Vehicles
Class TestVehicles
Private Shared Sub Main()
Dim myCar As Car = New Car()
myCar.Drive()
Dim mySportsCar As Sportscar = New Sportscar()
mySportsCar.Drive()
Dim myVan As Van = New Van()
myVan.Drive()
Dim myMiniVan As Minivan = New Minivan()
myMiniVan.Drive()
Dim myExcursionVan As ExcursionVan = New ExcursionVan()
myExcursionVan.Drive()
End Sub
End Class
End Namespace
Namespace Vehicles
Class Van
Inherits Vehicle
End Class
End Namespace
Namespace Vehicles
Class Vehicle
Protected make As String
Protected model As String
Protected year As String
Public Sub New()
End Sub
Public Sub New(ByVal make As String, ByVal model As String, ByVal year As String)
Me.make = make
Me.model = model
Me.year = year
End Sub
Public Property Make As String
Set(ByVal value As String)
make = value
End Set
Get
Return make
End Get
End Property
Public Property Model As String
Set(ByVal value As String)
model = value
End Set
Get
Return model
End Get
End Property
Public Property Year As String
Set(ByVal value As String)
year = value
End Set
Get
Return year
End Get
End Property
Public Sub Accelerate()
End Sub
Public Sub Decelerate()
End Sub
Public Sub Drive()
End Sub
Public Sub Start()
End Sub
Public Sub [Stop]()
End Sub
End Class
End Namespace