Clase Vehículos Ejercicio VB.Net - Curso de Programación Visual Basic

 Ejercicio

Clase Vehículos

Objetivo

Con Visual Studio, cree un proyecto y las clases correspondientes (con varios archivos) para este diagrama de clases. Cada clase debe incluir los atributos y métodos que se muestran en el diagrama, así como los métodos Get y Set para los métodos Vehicle y "Has" ("HasDualSlidingDoors") para MiniVan.

Debe crear también un programa de prueba, que creará un objeto perteneciente a cada clase y le dirá "Drive".

Código

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

Juan A. Ripoll - Tutoriales de Sistemas y Cursos de Programación© 2024 Todos los derechos reservados.  Condiciones legales.