Public Class frmGrades
  Dim pupil As Student  'pupil is an object of class Student

  Structure Person
    Dim name As String
    Dim socSecNum As String
    Dim semGrade As String
  End Structure

  Private Sub btnEnter_Click(ByVal sender As System.Object,
                             ByVal e As System.EventArgs) Handles btnEnter.Click
    'Create an instance of student
    'Read the values stored in the text boxes
    pupil = New Student()
    pupil.Name = txtName.Text
    pupil.SocSecNum = mtxtSSN.Text
    pupil.Midterm = CDbl(txtMidterm.Text)
    pupil.Final = CDbl(txtFinal.Text)
    'Clear text boxes and list box
    txtName.Clear()
    mtxtSSN.Clear()
    txtMidterm.Clear()
    txtFinal.Clear()
    'lstGrades.Items.Clear()
    MessageBox.Show("Student Recorded.")
  End Sub

  Private Sub btnDisplay_Click(ByVal sender As System.Object,
                               ByVal e As System.EventArgs) Handles btnDisplay.Click
    Dim persons(0) As Person
    persons(0).name = pupil.Name
    persons(0).socSecNum = pupil.SocSecNum
    persons(0).semGrade = pupil.CalcSemGrade
    Dim query = From someone In persons
                Select someone.name, someone.socSecNum, someone.semGrade
    dgvGrades.DataSource = query.ToList
    dgvGrades.CurrentCell = Nothing
    dgvGrades.Columns("name").HeaderText = "Student Name"
    dgvGrades.Columns("socSecNum").HeaderText = "SSN"
    dgvGrades.Columns("semGrade").HeaderText = "Grade"
  End Sub

  Private Sub btnQuit_Click(ByVal sender As System.Object,
                            ByVal e As System.EventArgs) Handles btnQuit.Click
    Me.Close()
  End Sub

End Class     'frmGrades


Class Student
  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
    Get
      Return m_name
    End Get
    Set(ByVal value As String)
      m_name = value
    End Set
  End Property

  Public Property SocSecNum() As String
    Get
      Return m_ssn
    End Get
    Set(ByVal value As String)
      m_ssn = value
    End Set
  End Property

  Public WriteOnly Property Midterm() As Double
    Set(ByVal value As Double)
      m_midterm = value
    End Set
  End Property

  Public WriteOnly Property Final() As Double
    Set(ByVal value As Double)
      m_final = value
    End Set
  End Property

  Function CalcSemGrade() As String
    Dim grade As Double
    grade = (m_midterm + m_final) / 2
    grade = Math.Round(grade)  'Round the grade
    If grade >= 60 Then
      Return "Pass"
    Else
      Return "Fail"
    End If
  End Function

End Class     'Student
