Create a program to calculate batting statistics.

Hits = singles + doubles + triples + home runs

At bats = plate appearances - sacrifices - base on balls - hit by pitch

Average = hits / at bats and is displayed with three decimals

Total bases = singles + (doubles * 2) + (triples times * 3) + (home runs * 4)

On-base percentage = hits / plate appearances and is displayed with three decimals

Slugging percentage = total bases / at bats and is displayed with three decimals

Use functions and procedures when possible. Your program should have at least one function and one

procedure. Do the proper desk checking to ensure that each calculation is correct.

Public Class frmBattingAverage Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click ' Exit and close program Me.Close() End Sub Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverage.Click ' Declare variables Dim Singles As Double Dim Doubles As Double Dim Triples As Double Dim HomeRuns As Double Dim Hits As Double Dim PlateAppearances As Double Dim Sacrifices As Double Dim BaseOnBalls As Double Dim HitByPitch As Double Dim AtBats As Double Dim Average As Double Dim TotalBases As Double Dim OnBasePercentage As Double Dim SluggingPercentage As Double ' Receive input and associate with variables Singles = Val(txtSingles.Text) Doubles = Val(txtDoubles.Text) Triples = Val(txtTriples.Text) HomeRuns = Val(txtHomeRuns.Text) Hits = Val(lblHits.Text) PlateAppearances = Val(txtPlate.Text) Sacrifices = Val(txtSacrifices.Text) BaseOnBalls = Val(txtBaseBalls.Text) HitByPitch = Val(txtHitPitch.Text) AtBats = Val(lblAtBats.Text) Average = Val(lblAverage.Text) 'OnBasePercentage = Val(lblOnBasePercent.Text) ' SluggingPercentage = Val(lblSlugPercent.Text) TotalBases = Val(lblTotalBases.Text) ' Perform calculations AtBats = PlateAppearances - Sacrifices - BaseOnBalls - HitByPitch Average = Hits / AtBats ' display with three decimals TotalBases = Singles + (Doubles * 2) + (Triples * 3) + (HomeRuns * 4) OnBasePercentage = Hits / PlateAppearances ' display with three decimals SluggingPercentage = TotalBases / AtBats ' display with three decimals ' Display results lblAtBats.Text = AtBats lblAverage.Text = Average lblOnBasePercent.Text = FormatPercent(OnBasePercentage, 2, True, True, True) lblSlugPercent.Text = FormatPercent(SluggingPercentage, 3, True, True, True) lblTotalBases.Text = TotalBases End Sub Public Function Hits(ByVal HitDoubles As Double, ByVal Singles As Double, ByVal Triples As Double, ByVal Homeruns As Double) As Double ' Calculate the number of hits Return Singles + HitDoubles + Triples + Homeruns lblHits.Text = Hits End Function End Class