Waterglen Horse Farms Each year, Sabrina Cantrell, the owner of Waterglen Horse
ID: 3831360 • Letter: W
Question
Waterglen Horse Farms
Each year, Sabrina Cantrell, the owner of Waterglen Horse Farms, enters four of her horses in five local horse races. She uses this table below to keep track of her horses’
performances in each race. In the table, a 1 indicates that 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. For example , according to the table horse 1 won one race, finished second in one race, finished third in one race, and didn’t finish in the top three in two races. Overall, Sabrina’s horses won four races, finished second in three races, finished third in three races, and didn’t finish in the top three in 10 races. Be sure to use one or more arrays in the application. Use the following names for the solution and project, respectively: Waterglen Solution and Waterglen Project. Change the form file’s name to Main Form.vb.
Needing the layout of the user interface with the names of the labels, buttons, etc. And the code that makes the program work.
1 2 3 4 5 1 0 1 0 3 2 2 1 0 2 0 0 3 0 3 0 1 0 4 3 2 1 0 0Explanation / Answer
Public Class Form1
Private horseStat(,) As Integer = {{0, 1, 0, 3, 2}, {1, 0, 2, 0, 0}, {0, 3, 0, 1, 0}, {3, 2, 1, 0, 0}}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
horseListbox.Items.Add("Horse 1")
horseListbox.Items.Add("Horse 2")
horseListbox.Items.Add("Horse 3")
horseListbox.Items.Add("Horse 4")
horseListbox.Items.Add("All horses")
horseListbox.SelectedIndex = 0
End Sub
Private Sub horseListbox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles horseListbox.SelectedIndexChanged
End Sub
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click
Dim firstplace As Integer = 0
Dim secondplace As Integer = 0
Dim thirdplace As Integer = 0
Dim noplacecount As Integer = 0
Dim selectedhorse As Integer = horseListbox.SelectedIndex
Dim highestSub As Integer = horseStat.GetUpperBound(0)
Dim highestcol As Integer = horseStat.GetUpperBound(1)
For raceIndex As Integer = 0 To highestSub
If horseStat(selectedhorse, 0) = 1 Then
firstplace += 1
ElseIf horseStat(selectedhorse, 0) = 2 Then
secondplace += 1
ElseIf horseStat(selectedhorse, 0) = 3 Then
thirdplace += 1
Else
noplacecount += 1
End If
Next
firstLabel.Text = firstplace
secondLabel.Text = secondplace
thirdLabel.Text = thirdplacenotLabel.Text = noplacecount
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.