Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Visual Basic program similar to the one described below. Write a functi

ID: 3881898 • Letter: C

Question

Create a Visual Basic program similar to the one described below.

Write a function to calculate the fine for speeding. The fine is $35 plus $10 per mile for every mile over the speed limit up to ten miles over the speed limit. When the speed is more than ten miles over the speed limit, the fine is $135 plus $20 per mile for every mile over the speed limit plus ten miles per hour. Pass the speed and the speed limit to the function. Have function determine the fine and return that value. The output is the amount of the fine.

Explanation / Answer

Dear student find inline comments to understand calculate fine function in given program.

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text.RegularExpressions

Namespace Rextester
Public Module Program
Public Sub Main(args() As string)
  
Console.WriteLine(calculateFine(150,115)) 'calling function to calculate fine passing 150 as speed and 115 is the limit
End Sub
'Below is the function to calculate fine based on speed and speed limit per hour
Private Function calculateFine( speed As Integer , limit As Integer) As Integer
Dim totalFine As Integer = 0 ' Defining variable to hold total calculated fine to return back to caller
If speed > limit and (speed-limit)<=10 Then 'checking condition to validate overspeed is less than 10 over specified limit
totalFine = 35+(10*(speed-limit))
Else If speed > limit and (speed-limit)>10 Then 'checking condition to validate overspeed is greater than than 10 over specified limit
totalFine = 135+(20*(speed-limit))
End If
Return totalFine 'returning calculated fine
End Function
End Module
End Namespace