Module Module1
Class tape
Dim length As String
Dim title As String
Dim year As String
Dim producer As String
Sub New()
End Sub
Sub New(ByVal lengthValue As String, ByVal sTitle As String, _
ByVal sYear As String, ByVal sProducer As String)
length = lengthValue
title = sTitle
year = sYear
producer = sProducer
End Sub
Sub setAttributes(ByVal lengthValue As String, ByVal sTitle As String, _
ByVal sYear As String, ByVal sProducer As String)
length = lengthValue
title = sTitle
year = sYear
producer = sProducer
End Sub
Sub printAttributes()
Console.WriteLine("Titolo: '" & title & "' durata di " & length & " circa " _
& ", anno: " & year & ", regista: " & producer)
End Sub
Function getTitle() As String
Return title
End Function
Function getLength() As String
Return length
End Function
Function getYear() As String
Return year
End Function
Function getProducer() As String
Return producer
End Function
End Class
Class MyBlockBuster
Dim films() As tape
Dim filmNumber As Integer
Sub New()
filmNumber = 0
Array.Resize(films, filmNumber)
End Sub
Sub AddFilm(ByVal film As tape)
Array.Resize(films, filmNumber + 1)
films(filmNumber) = film
filmNumber += 1
End Sub
Function getFilmNumber() As Integer
Return filmNumber
End Function
Sub ShowAllFilm()
For Each curr_film As tape In films
curr_film.printAttributes()
Next
End Sub
Function searchFilm(ByVal title As String) As tape
For Each curr_film As tape In films
If title = curr_film.getTitle() Then
Return curr_film
End If
Next
Return New tape("-", "-", "-", "-")
End Function
End Class
Dim BB As MyBlockBuster
Dim quit As Boolean = False
Sub addFilm()
Console.Clear()
Console.Write("Scrivi il titolo: ")
Dim title As String = Console.ReadLine()
Console.Write("Durata: ")
Dim length As String = Console.ReadLine()
Console.Write("Regista: ")
Dim producer As String = Console.ReadLine()
Console.Write("Anno: ")
Dim year As String = Console.ReadLine()
BB.AddFilm(New tape(length, title, year, producer))
Console.WriteLine("Film aggiunto all'archivio!")
Console.ReadKey()
Console.Clear()
End Sub
Sub searchFilm()
Console.Clear()
Console.Write("Scrivi il titolo: ")
Dim title As String = Console.ReadLine()
BB.searchFilm(title).printAttributes()
Console.ReadKey()
Console.Clear()
End Sub
Sub menu()
Console.WriteLine("------Gestione libreria film-------")
Console.WriteLine("Aggiungi film: A")
Console.WriteLine("Elenca i film: E")
Console.WriteLine("Cerca film: C")
Console.WriteLine("Esci: Q")
Dim command As Char = Char.ToUpper(Console.ReadKey().KeyChar)
Console.ReadKey() 'funzione aggiunta per fermare l'esecuzione fino a che non si preme invio
Select Case command
Case "A"
addFilm()
Case "E"
Console.Clear()
Console.WriteLine("Nell'archivio ci sono " & BB.getFilmNumber() & " film")
BB.ShowAllFilm()
Console.ReadKey()
Console.Clear()
Case "C"
searchFilm()
Case "Q"
quit = True
End Select
End Sub
Sub Main()
Dim pearlHarbor As tape
pearlHarbor = New tape
pearlHarbor.setAttributes("2.30 minuti", "Pearl Harbor", "2001", "Micheal Bay")
BB = New MyBlockBuster
BB.AddFilm(pearlHarbor)
Do
menu()
If quit = True Then
Exit Do
End If
Loop
End Sub
End Module