I need an aplication that allows Professor Carver to display a student\'s grade
ID: 664371 • Letter: I
Question
I need an aplication that allows Professor Carver to display a student's grade based on the number of points the student enters. The grading scale is minimum points to maximum points and the grading scale is 0-299 = F 300-349 = D 350 - 399 = C 400- 449 = B 450 - 500 = A Declare two class-level arrays: a one-dimensional Integer array named points and a one-dimensional String array named grades. The displayButton_Click procedure should search the points array and then display the corresponding grade from the grades array.
Here is my code so far
Option Explicit On
Option Strict On
Option Infer Off
Public Class MainForm
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub pointsTextBox_Enter(sender As Object, e As EventArgs) Handles pointsTextBox.Enter
pointsTextBox.SelectAll()
End Sub
Private Sub pointsTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles pointsTextBox.KeyPress
' accepts only numbers and the Backspace key
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub pointsTextBox_TextChanged(sender As Object, e As EventArgs) Handles pointsTextBox.TextChanged
gradeLabel.Text = String.Empty
End Sub
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click
Dim points() As Integer = {0, 300, 350, 400, 450}
Dim minPoints As Integer = points.GetUpperBound(0)
Dim grades(4,0) As String
For x As Integer = 1 To minPoints
If points(x) = minPoints Then
grades +-= 1
End If
Next x
End Sub
End Class
Explanation / Answer
Your displayButton_Click method needs to be modified to display correct grades based upon the points entered. Below is the modified code:-
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click
Dim points() As Integer = {0, 300, 350, 400, 450}
Dim grades() As String ={"F","D","C","B","A"}
Dim point As Integer = pointsTextBox.Text;
If point>=points(0) And point<points(1) Then
gradeLabel.Text=grades(0)
Else If point>=points(1) And point<points(2) Then
gradeLabel.Text=grades(1)
Else If point>=points(2) And point<points(3) Then
gradeLabel.Text=grades(2)
Else If point>=points(2) And point<points(3) Then
gradeLabel.Text=grades(3)
Else
gradeLabel.Text=grades(4)
End If
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.