Write a program so that calculates the distance traveled per hour. 1. In the CLI
ID: 3551901 • Letter: W
Question
Write a program so that calculates the distance traveled per hour.
1. In the CLICK event for the FOR-Up button, you must use FOR/NEXT to perform the operations as described in the book on page 347 listing the items in ascending order.
2. In the CLICK event for the FOR-Down button, you must use FOR/NEXT to perform the operations as described in the book on page 347 listing the items in descending order.
3. In the CLICK event for the DO-While button, you must use DO/WHILE to perform the operations as described in the book on page 347 listing the items in ascending order.
4. In the CLICK event for the DO-Until button, you must use DO/UNTIL to perform the operations as described in the book on page 347 listing the items in descending order.
5. In the CLICK events for all Calculate buttons, before performing any calculations, you must:
a. Validate the speed entered by the user:
i. Must be a whole number greater than zero.
ii. If invalid, issue a message and exit the procedure.
b. Validate the hours entered by the user:
i. Must be a whole number greater than zero.
ii. If invalid, issue a message and exit the procedure.
c. Must clear the Listbox before adding any items to it.
Should look like this....
The output in the List Box should look something like this:
Vehicle speed: 40 MPH
Time traveled: 7 hours
Hours Distance Traveled
__________________________
1 40
2 80
3 120
4 160
5 200
6 240
7 280
Explanation / Answer
'VB-01 Public Class frmDistanceCalculator Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim decDistanceTravelled As Decimal Dim decNumberofHoursInput As Decimal Dim decMPHSpeedInput As Decimal Dim intCounter As Integer = 1 Dim decTotalDistance As Decimal = 0 Dim blnFlag As Boolean Try For intCounter = 1 To decNumberofHoursInput decMPHSpeedInput = InputBox("Please enter your average rate speed in MPH", "Speed") decNumberofHoursInput = InputBox("Please enter the number of hours you spent", "Hours") If IsNumeric(decMPHSpeedInput) Or decNumberofHoursInput < 0 Then MessageBox.Show("Please enter a number greater than zero.") Else 'Calculation decDistanceTravelled = decNumberofHoursInput * decMPHSpeedInput 'Listbox blnFlag = True lstOutput.Items.Add("Vehicle Speed:" & decMPHSpeedInput.ToString & "MPH" & "Time Travelled:" & ControlChars.CrLf _ & decNumberofHoursInput.ToString & "hours" & ControlChars.CrLf & "Hours" & "Distance Travelled" & ControlChars.CrLf _ & "******************************************") Do While decNumberofHoursInput > 1 decNumberofHoursInput = decNumberofHoursInput - 1 Loop Do While blnFlag = True lstOutput.Items.Add(decNumberofHoursInput.ToString) blnFlag = False Loop End If 'If IsNumeric(decNumberofHoursInput) And IsNumeric(decMPHSpeedInput) Then ' If decNumberofHoursInput < 0 Then ' MessageBox.Show("Please enter a number greater than zero.") ' Else ' decDistanceTravelled = decNumberofHoursInput * decMPHSpeedInput ' End If 'End If 'Output If intCounter = decNumberofHoursInput Then lstOutput.Items.Add("Total Distance: " & decTotalDistance.ToString) End If Next Catch ex As Exception End Try End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub End ClassRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.