Public Class bbdd
  Private Shared alumnos As List(Of Alumno) = ObtenerAlumnos()

  ' Crear la base de datos
  Public Shared Function ObtenerAlumnos() As List(Of Alumno)
    alumnos = New List(Of Alumno)()
    Dim asignaturas As List(Of Asignatura) = Nothing
    Dim rnd As New Random()
    For i As Integer = 1 To 9
      Dim id As Integer = i + i * 10 + i * 100 ' 111, 222,...
      asignaturas = New List(Of Asignatura)()
      For a As Integer = 1 To rnd.Next(3, 8) - 1
        Dim asig As String = "Asignatura " & a ' Asignatura 1,...
        Dim nota As Single = CSng(CInt(rnd.NextDouble() * 100) / 10.0F)
        asignaturas.Add(New Asignatura(asig, nota))
      Next
      alumnos.Add(New Alumno(id, asignaturas))
    Next
    Return alumnos
  End Function

  Public Shared Function ObtenerAlumnoPorId(id As Integer) As Alumno
    ' Predicado anónimo
    Dim alumno As Alumno = alumnos.Find(Function(al As Alumno) al.IdAlumno = id)
    Return alumno
  End Function

  Public Shared Function ObtenerAsigsAlumno(id As Integer) As List(Of Asignatura)
    Dim alumno As Alumno = ObtenerAlumnoPorId(id)
    If alumno Is Nothing Then
      Return Nothing
    End If
    Return alumno.ListaAsignaturas
  End Function

  Public Shared Function ObtenerAsignatura(id As Integer, nomAsig As String) As Asignatura
    Dim listaAsigs As List(Of Asignatura) = ObtenerAsigsAlumno(id)
    ' Predicado anónimo
    Dim asignatura As Asignatura = listaAsigs.Find(Function(asign As Asignatura) asign.NomAsignatura = nomAsig)
    Return asignatura
  End Function
End Class
