Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Gestione Libreria Film - Module1.vb

Module1.vb

Caricato da: Carlduke
Scarica il programma completo

  1. Module Module1
  2.     Class tape
  3.         Dim length As String
  4.         Dim title As String
  5.         Dim year As String
  6.         Dim producer As String
  7.  
  8.         Sub New()
  9.  
  10.         End Sub
  11.  
  12.         Sub New(ByVal lengthValue As String, ByVal sTitle As String, _
  13.                           ByVal sYear As String, ByVal sProducer As String)
  14.             length = lengthValue
  15.             title = sTitle
  16.             year = sYear
  17.             producer = sProducer
  18.  
  19.         End Sub
  20.  
  21.         Sub setAttributes(ByVal lengthValue As String, ByVal sTitle As String, _
  22.                           ByVal sYear As String, ByVal sProducer As String)
  23.             length = lengthValue
  24.             title = sTitle
  25.             year = sYear
  26.             producer = sProducer
  27.         End Sub
  28.  
  29.         Sub printAttributes()
  30.             Console.WriteLine("Titolo: '" & title & "' durata di " & length & " circa " _
  31.                               & ", anno: " & year & ", regista: " & producer)
  32.         End Sub
  33.  
  34.         Function getTitle() As String
  35.             Return title
  36.         End Function
  37.  
  38.         Function getLength() As String
  39.             Return length
  40.         End Function
  41.  
  42.         Function getYear() As String
  43.             Return year
  44.         End Function
  45.  
  46.         Function getProducer() As String
  47.             Return producer
  48.         End Function
  49.  
  50.     End Class
  51.  
  52.     Class MyBlockBuster
  53.         Dim films() As tape
  54.         Dim filmNumber As Integer
  55.  
  56.         Sub New()
  57.             filmNumber = 0
  58.             Array.Resize(films, filmNumber)
  59.         End Sub
  60.  
  61.         Sub AddFilm(ByVal film As tape)
  62.             Array.Resize(films, filmNumber + 1)
  63.             films(filmNumber) = film
  64.             filmNumber += 1
  65.         End Sub
  66.  
  67.         Function getFilmNumber() As Integer
  68.             Return filmNumber
  69.         End Function
  70.  
  71.         Sub ShowAllFilm()
  72.             For Each curr_film As tape In films
  73.                 curr_film.printAttributes()
  74.             Next
  75.         End Sub
  76.  
  77.         Function searchFilm(ByVal title As String) As tape
  78.             For Each curr_film As tape In films
  79.                 If title = curr_film.getTitle() Then
  80.                     Return curr_film
  81.                 End If
  82.             Next
  83.  
  84.             Return New tape("-", "-", "-", "-")
  85.         End Function
  86.     End Class
  87.  
  88.     Dim BB As MyBlockBuster
  89.     Dim quit As Boolean = False
  90.  
  91.     Sub addFilm()
  92.         Console.Clear()
  93.         Console.Write("Scrivi il titolo: ")
  94.         Dim title As String = Console.ReadLine()
  95.  
  96.         Console.Write("Durata: ")
  97.         Dim length As String = Console.ReadLine()
  98.  
  99.         Console.Write("Regista: ")
  100.         Dim producer As String = Console.ReadLine()
  101.  
  102.         Console.Write("Anno: ")
  103.         Dim year As String = Console.ReadLine()
  104.  
  105.         BB.AddFilm(New tape(length, title, year, producer))
  106.  
  107.         Console.WriteLine("Film aggiunto all'archivio!")
  108.         Console.ReadKey()
  109.         Console.Clear()
  110.     End Sub
  111.  
  112.     Sub searchFilm()
  113.         Console.Clear()
  114.  
  115.         Console.Write("Scrivi il titolo: ")
  116.         Dim title As String = Console.ReadLine()
  117.  
  118.         BB.searchFilm(title).printAttributes()
  119.  
  120.         Console.ReadKey()
  121.         Console.Clear()
  122.     End Sub
  123.  
  124.     Sub menu()
  125.         Console.WriteLine("------Gestione libreria film-------")
  126.         Console.WriteLine("Aggiungi film: A")
  127.         Console.WriteLine("Elenca i film: E")
  128.         Console.WriteLine("Cerca film: C")
  129.         Console.WriteLine("Esci: Q")
  130.  
  131.         Dim command As Char = Char.ToUpper(Console.ReadKey().KeyChar)
  132.         Console.ReadKey() 'funzione aggiunta per fermare l'esecuzione fino a che non si preme invio
  133.  
  134.         Select Case command
  135.             Case "A"
  136.                 addFilm()
  137.             Case "E"
  138.                 Console.Clear()
  139.                 Console.WriteLine("Nell'archivio ci sono " & BB.getFilmNumber() & " film")
  140.                 BB.ShowAllFilm()
  141.                 Console.ReadKey()
  142.                 Console.Clear()
  143.             Case "C"
  144.                 searchFilm()
  145.             Case "Q"
  146.                 quit = True
  147.         End Select
  148.     End Sub
  149.  
  150.     Sub Main()
  151.         Dim pearlHarbor As tape
  152.         pearlHarbor = New tape
  153.         pearlHarbor.setAttributes("2.30 minuti", "Pearl Harbor", "2001", "Micheal Bay")
  154.  
  155.         BB = New MyBlockBuster
  156.  
  157.         BB.AddFilm(pearlHarbor)
  158.  
  159.         Do
  160.             menu()
  161.             If quit = True Then
  162.                 Exit Do
  163.             End If
  164.         Loop
  165.     End Sub
  166. End Module