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

A gas pump calculates the cost of gas at a local gas station. The station charge

ID: 3558659 • Letter: A

Question

A gas pump calculates the cost of gas at a local gas station. The station charges $2.69 per gallon for regular grade gas, $2.79 per gallon for special grade gas and $2,89 per gallon for super grade gas. Create an application that simulates the functionality of the gas pump. The user enters the number of gallons to purchase and clicks the desired grade (each grade is represented by a Button whose Text properties are set to Regular, Special and Super). Each Button's Click event handler calls a method to compute the total cost from the number of gallons entered and the selected grade. [Note: Use the Text property of each Button to pass the selected grade to your method.]"

Explanation / Answer

Public Class Form1 02 03     Dim gallons As Double ' total gallons 04     Dim total As Decimal ' total price gallons times grade price 05     Dim regular As Decimal = 2.69 06     Dim special As Decimal = 2.79 07     Dim super As Decimal = 2.89 08 09     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 10         Cal(Val(gallonsTextBox.Text), Val(resultLabel.Text), 0) 11     End Sub 12 13 14     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 15         Cal(Val(gallonsTextBox.Text), Val(resultLabel.Text), 1) 16     End Sub 17 18     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 19         Cal(Val(gallonsTextBox.Text), Val(resultLabel.Text), 2) 20     End Sub 21 22 23 24     Private Sub Cal(ByVal num1 As Integer, ByVal num2 As Integer, ByVal ops As Integer) 25         Do While gallons > 0 26 27 28             Select Case ops 29                 Case 0 30                     resultLabel.Text = gallons * regular 31                 Case 1 32                     resultLabel.Text = gallons * special 33                 Case 2 34                     resultLabel.Text = gallons * super 35             End Select 36         Loop 37     End Sub 38 39      40      41 End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote