Block of Code

Practical Examples for Programmers

  • Home
  • C++
  • Java
  • Visual Basic
  • Discrete Math
  • Ask a Question

Repair Bill

Complete this assignment using Visual Basic. Suppose automobile repair customers are billed at the rate of $35 per hour for labor. Also, suppose costs for parts and supplies are subject to a 5% sales tax. Write a program to display a simplified bill. The customer’s name, the number of hours of labor, and the cost of parts and supplies should be entered into the program via text boxes. When a button is clicked, the customer’s name and the three costs should be displayed in a list box, as shown below.

Design the Interface:

First we need to design the interface.  The following image shows an example of what the form might look like when the program runs.

Repair Bill

Suggested Control Names and Attributes:

Name Property Text Property Control Type Notes
frmBill Auto Repair Form Holds Controls
txtCustomer Text Box Captures customer’s name entered
txtHours Text Box Captures # of hours of labor entered
txtCost Text Box Captures cost of parts and supplies entered
btnDisplay Display Bill Button Triggers the event for displaying bill
lstBill List Box Displays customer’s bill

Write the Code:

' Project: Auto Repair
' Description: Simulates an auto repair bill from user input.
' Name, hours of labor and cost of supplies are input by the user.
' Total cost is calculated and output to the screen with proper formatting.

Public Class frmBill

   Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
      Const LABOR_RATE As Double = 35.0 'Constant for cost of labor
      Dim hours As Double = CDbl(txtHours.Text)
      Dim laborCost As Double = LABOR_RATE * hours
      Dim partsCost As Double = CDbl(txtCost.Text)
      Dim totalCost As Double = laborCost + partsCost 'Variable to calculate total cost
      lstBill.Items.Clear()
      lstBill.Items.Add("Customer " & txtCustomer.Text)
      lstBill.Items.Add("Labor Cost " & laborCost.ToString("C"))
      lstBill.Items.Add("Parts Cost " & partsCost.ToString("C"))
      lstBill.Items.Add("Total Cost " & totalCost.ToString("C"))
   End Sub

End Class

Secondary Sidebar

This is the secondary sidebar

Copyright © 2025 · Metro Pro Theme on Genesis Framework · WordPress · Log in