Public Class frmGrades
  Dim students(50) As Student           'Stores the class
  Dim lastStudentAdded As Integer = -1  'Last student added to students()

  Private Sub btnEnter_Click(ByVal sender As System.Object,
                             ByVal e As System.EventArgs) Handles btnEnter.Click
    'Stores a student into the array.
    Dim pupil As Student
    'Create the appropriate object depending upon the radio button.
    If radPassFail.Checked Then
      pupil = New PFStudent()
    Else
      pupil = New Student()
    End If
    'Store the values in the text boxes into the object.
    pupil.Name = txtName.Text
    pupil.SocSecNum = mtbSSN.Text
    pupil.Midterm = CDbl(txtMidterm.Text)
    pupil.Final = CDbl(txtFinal.Text)
    'Add the student to the array.
    lastStudentAdded += 1
    students(lastStudentAdded) = pupil
    'Clear text boxes and list box.
    txtName.Clear()
    mtbSSN.Clear()
    txtMidterm.Clear()
    txtFinal.Clear()
    MessageBox.Show("Student #" & lastStudentAdded + 1 &
                                  " recorded.")
    txtName.Focus()
  End Sub

  Private Sub btnDisplay_Click(ByVal sender As System.Object,
                               ByVal e As System.EventArgs) Handles btnDisplay.Click
    'Display the students' information and semester grade
    ReDim Preserve students(lastStudentAdded)
    Dim query = From pupil In students
                Select pupil.Name, pupil.SocSecNum, pupil.CalcSemGrade
    dgvGrades.DataSource = query.ToList
    dgvGrades.CurrentCell = Nothing
    dgvGrades.Columns("Name").HeaderText = "Student Name"
    dgvGrades.Columns("SocSecNum").HeaderText = "SSN"
    dgvGrades.Columns("CalcSemGrade").HeaderText = "Grade"
    ReDim Preserve students(50)
    txtName.Focus()
  End Sub

  Private Sub btnQuit_Click(ByVal sender As System.Object,
                            ByVal e As System.EventArgs) Handles btnQuit.Click
    'Quit the program
    Me.Close()
  End Sub
End Class     'frmGrades

Class Student
  'Member variables to hold the property values
  'Private m_name As String
  'Private m_ssn As String
  Private m_midterm As Double
  Private m_final As Double

  Public Property Name() As String
  '  'The student's name
  '  Get
  '    Return m_name
  '  End Get
  '  Set(ByVal value As String)
  '    m_name = value
  '  End Set
  'End Property

  Public Property SocSecNum() As String
  '  'The student's Social Security Number
  '  Get
  '    Return m_ssn
  '  End Get
  '  Set(ByVal value As String)
  '    m_ssn = value
  '  End Set
  'End Property

  Public WriteOnly Property Midterm() As Double
    'The student's score on the midterm exam
    Set(ByVal value As Double)
      m_midterm = value
    End Set
  End Property

  Public WriteOnly Property Final() As Double
    'The student's score on the final exam
    Set(ByVal value As Double)
      m_final = value
    End Set
  End Property

  Overridable Function CalcSemGrade() As String
    'The student's grade for the semester
    Dim grade As Double
    'The grade is based upon average of the midterm and final exams.
    grade = (m_midterm + m_final) / 2
    grade = Math.Round(grade)  'Round the grade.
    Select Case grade
      Case Is >= 90
        Return "A"
      Case Is >= 80
        Return "B"
      Case Is >= 70
        Return "C"
      Case Is >= 60
        Return "D"
      Case Else
        Return "F"
    End Select
  End Function
End Class     'Student

Class PFStudent
  Inherits Student

  Overrides Function CalcSemGrade() As String
    'The student's grade for the semester
    If MyBase.CalcSemGrade = "F" Then
      Return "Fail"
    Else
      Return "Pass"
    End If
  End Function
End Class     'PFStudent
