Create a Trip Calculator Windows application using visual studio that can be use
ID: 3693938 • Letter: C
Question
Create a Trip Calculator Windows application using visual studio that can be used to determine miles per gallon for a given trip. Set the Form object properties of Name, ForeColor, BackColor, Size, Location, Text, and AcceptButton. The form should contain labels and textboxes to allow the user to input trip destination, miles traveled, and gallons of gas consumed. Right justify the number entries. Left justify the destination entry. Two buttons should be placed on the form. Center the text on the button objects. Name all objects used in program statements. When the user clicks the button that performs the calculations, display on a label the miles per gallon for that trip. The second button should be used to reset or clear all textbox entries.
Explanation / Answer
Public Class MilesPerGallonForm
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles calculateButton.Click
Dim miles As Double
Dim gallons As Double
Dim mpg As Double
miles = Val(milesTextBox.Text)
gallons = Val(gallonsTextBox.Text)
' if any of the values received are less than or equal to zero
If (miles <= 0) OrElse (gallons <= 0) Then
MessageBox.Show("Please enter a valid amount",
"Invalid Amount Entered", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Else
' divide the miles driven by the gallons used
mpg = MilesPerGallon(miles, gallons)
outputLabel.Text = String.Format("{0:F}", mpg)
End If
End Sub ' calculateButton_Click
' Function procedure Divide is executed
Function MilesPerGallon(ByVal milesDriven As Double, ByVal gallonsUsed As Double) AsDouble
' return quotient of the miles driven divided by the gallons used
Return milesDriven / gallonsUsed
End Function ' MilesPerGallon
End Class ' MilesPerGallonForm
Objects used:
Assigned a data type
Name cannot be a reserved word start with a number, or special character
Boolean- true or false
Integer- non-floating point number
Double or decimal-floating point number
String- text
Public Class MilesPerGallonForm