Catalog VB.Net Exercise - Visual Basic Programming Course


 Exercise

Catalog

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

More VB.Net Exercises of OOP More On Classes

 Array of objects: table
Create a class named "Table". It must have a constructor, indicating the width and height of the board. It will have a method "ShowData" which will wr...
 House
Create a class "House", with an attribute "area", a constructor that sets its value and a method "ShowData" to display "I am a house, my area is 200 m...
 Table + coffetable + array
Create a project named "Tables2", based on the "Tables" project. In it, create a class "CoffeeTable" that inherits from "Table". Its method "ShowDa...
 Encrypter & Decrypter
Create a class "Encrypter" to encrypt and decrypt text. It will have a "Encrypt" method, which will receive a string and return another string. It ...
 Complex numbers
A complex number has two parts: the real part and the imaginary part. In a number such as a+bi (2-3i, for example) the real part would be "a" (2) and ...
 Table + coffetable + leg
Extend the example of the tables and the coffee tables, to add a class "Leg" with a method "ShowData", which will write "I am a leg" and then it will ...
 Random number
Create a class RandomNumber, with three static methods: - GetFloat will return a number between 0 and 1 using the following algorithm: seed = (s...
 Text to HTML
Create a class "TextToHTML", which must be able to convert several texts entered by the user into a HTML sequence, like this one: Hola Soy yo Ya ...
 Class ScreenText
Create a class ScreenText, to display a certain text in specified screen coordinates. It must have a constructor which will receive X, Y and the strin...
 Enhanced ComplexNumber class
Improve the "ComplexNumber" class, so that it overloads the operators + and - to add and subtract numbers....
 3D point
Create a class "Point3D", to represent a point in 3-D space, with coordinates X, Y and Z. It must contain the following methods: MoveTo, which will...
 Catalog + Menu
Improve the Catalog program, so that "Main" displays a menu to allow entering new data of any kind, as well as displaying all the data stored....


Juan A. Ripoll - Systems Tutorials and Programming Courses © 2024 All rights reserved.  Legal Conditions.