Question: In this exercise, you create an application that allows the user to enter two items of information for any number of students: whether the student

In this exercise, you create an application that allows the user to enter two items of information for any number of students: whether the student is a freshman or sophomore and the student's GPA. The application should calculate the average GPA for all students, the average GPA for freshmen, and the average GPA for sophomores. Create a Windows Forms application. Use the following names for the project and solution, respectively: GPA Project and GPA Solution. Save the application in the VB9e\Chap05 folder. The application's interface is shown in Figure 5-50. The list box should list GPAs from 1.0 through 4.0 in increments of 0.1(e.g.,1.0,1.1,1.2,1.3). Code the application. Save the solution and then start and test the application. (F5.1, F5.2, F5.5F5.7, A5.1A5.3). I'm attaching what I have coded so far, but calculations aren't being done corrctly. Please help!
Public Class frmMain
Dim allStudentsGpa As Double =0
Dim allStudentsCount As Integer =0
Dim FreshmanGpa As Double =0
Dim SophomoreGpa As Double =0
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim gpa As Double
If Double.TryParse(lstGpa.Text, gpa) AndAlso gpa >=0 AndAlso gpa =4.0 Then
Dim isFreshman As Boolean = rbFreshman.Checked
' Update total GPA and count
allStudentsGpa += gpa
allStudentsCount +=1
' Update either freshman or sophomore GPA
If isFreshman Then
FreshmanGpa += gpa
Else
SophomoreGpa += gpa
End If
' Display GPA in Listbox
lstGpa.Items.Add(gpa)
' Clear textboxes
lstGpa.Text =""
rbFreshman.Checked = False
rbSophomore.Checked = False
Else
MessageBox.Show("Invalid GPA. Please enter a valid GPA between 0 and 4.")
End If
' Calculate averages
If allStudentsCount >0 Then
Dim averageAllStudents As Double = allStudentsGpa / allStudentsCount
Dim averageFreshmen As Double = IIf(allStudentsCount =0,0, FreshmanGpa / allStudentsCount)
Dim averageSophomores As Double = IIf(allStudentsCount =0,0, SophomoreGpa / allStudentsCount)
' Update labels or textboxes to display the averages
lblAllStudents.Text = averageAllStudents.ToString("F2")
lblFreshmen.Text = averageFreshmen.ToString("F2")
lblSophomores.Text = averageSophomores.ToString("F2")
End If
End Sub
End Class
 In this exercise, you create an application that allows the user

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!