Catalog Learn programming Visual Basic (VB.net)

Lesson:

More On Classes


Exercise:

Catalog 13


Objetive:

Create the classes diagram and then, using Visual Studio, a project and the corresponding classes for a catalog utility:

It will be able to store information about music files, films and computer programs.
For each item, it must store: name, code, category and size. For films it must also hold the director, the main actor and the main actress. For music files, the singer and the length (in seconds).
For music and movies it must have a method "Play" (not implemented yet) and also a method "RetrieveInformation", which will (in a later version) connect to an internet server to get information about it.
Use inheritance if needed. In "Main", create arrays of each kind of object.


Code:

Imports System
Namespace Catalog
    Class TestItem
        Private Shared Sub Main()
            Dim myFilms As Film() = New Film(2) {}
            Dim myMusic As Music() = New Music(2) {}
            Dim myComputerProgram As ComputerProgram() = New ComputerProgram(2) {}
        End Sub
    End Class

    Public Class Item
        Protected name As String
        Protected code As String
        Protected category As String
        Protected size As String

        Public Sub New()
        End Sub

        Public Sub New(ByVal name As String, ByVal code As String, ByVal category As String, ByVal size As String)
            Me.name = name
            Me.code = code
            Me.category = category
            Me.size = size
        End Sub

        Public Property Name As String
            Get
                Return name
            End Get
            Set(ByVal value As String)
                name = value
            End Set
        End Property

        Public Property Code As String
            Get
                Return code
            End Get
            Set(ByVal value As String)
                code = value
            End Set
        End Property

        Public Property Category As String
            Get
                Return category
            End Get
            Set(ByVal value As String)
                category = value
            End Set
        End Property

        Public Property Size As String
            Get
                Return size
            End Get
            Set(ByVal value As String)
                size = value
            End Set
        End Property
    End Class

    Public Class Film
        Inherits Item

        Protected director As String
        Protected mainActor, mainActress As String

        Public Sub New()
        End Sub

        Public Sub New(ByVal director As String, ByVal mainActor As String, ByVal mainActress As String)
            Me.director = director
            Me.mainActor = mainActor
            Me.mainActress = mainActress
        End Sub

        Public Property Director As String
            Get
                Return director
            End Get
            Set(ByVal value As String)
                director = value
            End Set
        End Property

        Public Property MainActor As String
            Get
                Return mainActor
            End Get
            Set(ByVal value As String)
                mainActor = value
            End Set
        End Property

        Public Property MainActress As String
            Get
                Return mainActress
            End Get
            Set(ByVal value As String)
                mainActress = value
            End Set
        End Property

        Public Sub Play()
        End Sub

        Public Sub RetrieveInformation()
        End Sub
    End Class

    Public Class Music
        Inherits Item

        Protected singer As String
        Protected length As Integer

        Public Sub New()
        End Sub

        Public Sub New(ByVal singer As String, ByVal length As Integer)
            Me.singer = singer
            Me.length = length
        End Sub

        Public Property Singer As String
            Get
                Return singer
            End Get
            Set(ByVal value As String)
                singer = value
            End Set
        End Property

        Public Property Lenght As Integer
            Get
                Return length
            End Get
            Set(ByVal value As Integer)
                length = value
            End Set
        End Property

        Public Sub Play()
        End Sub

        Public Sub RetrieveInformation()
        End Sub
    End Class

    Public Class ComputerProgram
        Inherits Item
    End Class
End Namespace