' Dr Michael Redmond ' redmond@lasalle.edu ' 2/21/2007 ' Purpose: ' The NJ State Police, in conjunction with the EZ Pass system ' want to fine people based on traveling too many miles in too ' little time. This program gets from the user the number of ' minutes spent on the highway, the number of miles traveled, ' and the speed limit on the stretch of the Garden State Parkway ' traveled. The program then displays the speed and if the person ' was speeding the program then calculates the fine Option Explicit On Option Strict On Public Class Form1 Const lowBaseFine As Double = 20.0 Const highBaseFine As Double = 50.0 Const lowExtraFine As Double = 2.0 Const medExtraFine As Double = 4.0 Const highExtraFine As Double = 5.0 Const minLimit As Integer = 35 Const maxLimit As Integer = 70 Const fineDoubledLimit As Integer = 65 Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click txtMins.Clear() txtMiles.Clear() txtLimit.Clear() txtMph.Clear() txtFine.Clear() End Sub Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click ' declare variable Dim mins As Integer Dim miles As Integer Dim limit As Integer Dim isOkMins As Boolean Dim isOkMiles As Boolean Dim isOkLimit As Boolean Dim speed As Double Dim overLimit As Double Dim fine As Double ' get inputs isOkMins = Integer.TryParse(txtMins.Text, mins) isOkMiles = Integer.TryParse(txtMiles.Text, miles) isOkLimit = Integer.TryParse(txtLimit.Text, limit) ' validate inputs - process can be the same for each text box ' handle minutes If isOkMins Then ' check range If mins < 1 Then ' bad value - indicate problem isOkMins = False MsgBox("Please enter a positive number of minutes") End If Else MsgBox("Please enter a whole number for minutes") End If ' handle miles If isOkMiles Then ' check range If miles < 1 Then ' bad value - indicate problem isOkMiles = False MsgBox("Please enter a positive number of miles") End If Else MsgBox("Please enter a whole number for miles") End If ' handlespeed limit If isOkLimit Then ' check range If limit < minLimit Or limit > maxLimit Then ' bad value - indicate problem isOkLimit = False MsgBox("Please enter a speed limit between 35 and 70") End If Else MsgBox("Please enter a whole number for speed limit") End If ' calculate speed and fine - ' first make sure inputs are good - only go on if all inputs are good If isOkMins AndAlso isOkMiles AndAlso isOkLimit Then speed = miles / (mins / 60.0) ' calculate speed in mph ' calculate amount over speed limit overLimit = speed - limit ' calculate initial fine based on amount over limit Select Case overLimit Case Is <= 0 ' not speeding fine = 0 Case Is <= 5 ' speeding by 5 or less fine = lowBaseFine Case Is <= 10 ' speeding by more than 5 up to 10 fine = lowBaseFine + (overLimit * lowExtraFine) Case Is <= 20 ' speeding by more than 10 up to 20 fine = lowBaseFine + (overLimit * medExtraFine) Case Else ' speeding by more than 20 fine = highBaseFine + (overLimit * highExtraFine) End Select ' check for high speed limit - if so then double fine If limit >= fineDoubledLimit Then fine = fine * 2 End If ' display results txtMph.Text = speed.ToString("n1") txtFine.Text = fine.ToString("c2") End If End Sub End Class