Visual Basics Year 2017 24.1 Year 2016 34.9 Year 2015 31.4 Year 2014 29.9 Year 2
ID: 3834465 • Letter: V
Question
Visual Basics
Year 2017
24.1
Year 2016
34.9
Year 2015
31.4
Year 2014
29.9
Year 2013
34.2
Year 2012
48.2
Year 2011
36.4
Year 2010
47.0
Year 2009
38.4
Year 2008
30.7
Year 2007
39.0
Year 2006
48.8
Year 2005
35.4
Year 2004
31.1
Year 2003
41.8
Year 2002
31.4
Year 2001
37.6
Year 2000
28.7
Need help with a Rainfall project. A windows application will analyze rainfall totals from 2000-2017. The user can select a year from the range and view the total rainfall inches in that year. The average rainfall for the range of years and the rainest year are also displayed. The application first opens a txt.file on information from the national weather service. The file is names rain.txt, and it lists the total rainfall amounts in seattle washington during the years 2000-2017. The user can select a year in the range of data to view the total rainfall for that year. When the user taps the Display statistics button, the average rainfall for the year within the range and rainest year are displayed. Use two Sub methods to compute the average rainfall and the year with the most rainfall.
Explanation / Answer
the code for rainfall in visual basic is given below
public class Form
Dim strMonths() As String = {"January", "February", "March", "April", _
"May", "June", "July", "August", "September", "October", "November", _
"December"}
Dim intMonths(11) As Integer
Private Sub btnRainfall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRainfall.Click
'calculate and display monthly rainfall
Dim intCounter As Integer 'loop counter
Dim intRain As Integer 'amount of rain
lstRainfall.Items.Add("Monthly Rainfall Input")
lstRainfall.Items.Add("___________________________")
'get the rain for each month
Do While intCounter <= 11
Try
intRain = CInt(Val(InputBox("Please Enter the amount of Rainfall in Inches for " & strMonths(intCounter))))
lstRainfall.Items.Add((intRain).ToString() & " for " & strMonths(intCounter))
intMonths(intCounter) = intRain
intCounter += 1
Catch
MsgBox("Enter a valid numeric value.")
End Try
Loop
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim intCounter As Integer
Dim intMax As Integer = intMonths(0)
Dim intMin As Integer = intMonths(0)
Dim dblMonthlyavg As Double
Dim intTotal As Integer = 0
Dim minIndex As Integer = 0
Dim maxIndex As Integer = 0
'calculate maximum
For intCounter = 0 To (intMonths.Length - 1)
If intMonths(intCounter) > intMax Then
intMax = intMonths(intCounter)
maxIndex = intCounter
End If
Next intCounter
'calculate(minimum)
For intCounter = 0 To (strMonths.Length - 1)
If intMonths(intCounter) < intMin Then
intMin = intMonths(intCounter)
minIndex = intCounter
End If
Next intCounter
'calculate total rainfall
For intCounter = 0 To (strMonths.Length - 1)
intTotal += intMonths(intCounter)
Next intCounter
'Calculating the Rainfall Average
dblMonthlyavg = (intTotal / strMonths.Length)
txtTotal.Visible = True
txtAverage.Visible = True
txtMin.Visible = True
txtMax.Visible = True
'Filling in Variables to Text Boxes
txtTotal.Text = "The total annual rainfall was " & intTotal
txtAverage.Text = "The average monthly rainfall was " & dblMonthlyavg.ToString("r1")
txtMin.Text = "The minimum monthly rainfall was " & intMin & "(" & strMonths(minIndex) & ")"
txtMax.Text = "The maximum monthly rainfall was " & intMax & "(" & strMonths(maxIndex) & ")"
End Sub
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.