Each year, Sabrina Cantrell, the owner of Waterglen Horse Farms, enters four of
ID: 670791 • Letter: E
Question
Each year, Sabrina Cantrell, the owner of Waterglen Horse Farms, enters four of her horses in five local horse races. She uses a table similar to the one shown in Figure 20-23 to keep track of her horses' performances in each race. In the table, a 1 indicates the the horse won the race, a 2 indicates second place, and a 3 indicates third place. A 0 indicates that the horse did not finish in the top three places. Sabrina wants an application that displays a summary of each horse's individual performance, as well as the performances of all the horses.
txtNum = user input box
lblFirst, lblSecond, lblThird, lblNone = output box
btnDisplay = calc on click
Race 1 Race 2 Race 3 Race 4 Race 5 Horse 1 0 1 0 3 2 Horse 2 1 0 2 0 0 Horse 3 0 3 0 1 0 Horse 4 3 2 1 0 0Explanation / Answer
Option Explicit On
Option Strict Off
Option Infer Off
Public Class MainForm
Private raceTable(,) As String = {{"Horse 1", "0", "1", "0", "3", "2"},
{"Horse 2", "1", "0", "2", "0", "0"},
{"Horse 3", "0", "3", "0", "1", "0"},
{"Horse 4", "3", "2", "1", "0", "0"}}
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
'exit the application
Me.Close()
End Sub
Private Sub horsesListBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles horsesListBox.SelectedIndexChanged
'clear the finishes boxes
firstLabel.Text = String.Empty
secondLabel.Text = String.Empty
thirdLabel.Text = String.Empty
noPlaceLabel.Text = String.Empty
'display the horses' performance
Dim Subscript As Integer
Subscript = horsesListBox.SelectedIndex
firstLabel.Text = raceTable(Subscript, 0).ToString
secondLabel.Text = raceTable(Subscript, 1).ToString
thirdLabel.Text = raceTable(Subscript, 2).ToString
noPlaceLabel.Text = raceTable(Subscript, 3).ToString
End Sub
Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'fill the list box
horsesListBox.Items.Add("Horse 1")
horsesListBox.Items.Add("Horse 2")
horsesListBox.Items.Add("Horse 3")
horsesListBox.Items.Add("Horse 4")
horsesListBox.SelectedIndex = 0
End Sub
Private Sub displayButton_Click(sender As Object, e As System.EventArgs) Handles displayButton.Click
'displays how each horse placed
Dim highRowSub As Integer = raceTable.GetUpperBound(0)
Dim searchHorse As String
Dim horsePlacedFirst As String = "1"
Dim horsePlacedSecond As String = "2"
Dim horsePlacedThird As String = "3"
Dim horseNoPlace As String = "0"
searchHorse = horsesListBox.SelectedItem.ToString
For row As Integer = 0 To highRowSub
If raceTable(row, 0) = 1 Then
horsePlacedFirst = horsePlacedFirst &
raceTable(row, 0)
End If
Next row
'display how the horses placed
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.