You are on page 1of 1

Public Class frmBill

Const PIZZA_PRICE As Double = 1.75


Const FRIES_PRICE As Double = 2
Const DRINKS_PRICE As Double = 1.25
Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnCompute.Click
'Compute a customer's bill
Dim pizzaSlices As Double, fries As Double, softDrinks As Double
lstOutput.Items.Clear()
InputData(pizzaSlices, fries, softDrinks)
DisplayBill(pizzaSlices, fries, softDrinks)
End Sub
Sub DisplayBill(ByVal pizzaSlices As Double, ByVal fries As Double,
ByVal softDrinks As Double)
'Display an itemized bill
Dim total As Double
total = TotalCost(pizzaSlices, fries, softDrinks)
lstOutput.Items.Add("ITEM" & "
" & "QUANTITY" & " " & "PRICE")
lstOutput.Items.Add("pizza slices" & "
" & pizzaSlices &
"
" & FormatCurrency(PIZZA_PRICE * pizzaSlices))
lstOutput.Items.Add("fries" & "
" & fries &
"
" & FormatCurrency(FRIES_PRICE * fries))
lstOutput.Items.Add("soft drinks" & "
" & softDrinks &
"
" & FormatCurrency(DRINKS_PRICE * softDrinks))
lstOutput.Items.Add("TOTAL" & "
" & FormatCurrency(total))
End Sub
Sub InputData(ByRef pizzaSlices As Double, ByRef fries As Double, _
ByRef softDrinks As Double)
'Input items
pizzaSlices = CDbl(txtPizza.Text)
fries = CDbl(txtFries.Text)
softDrinks = CDbl(txtDrinks.Text)
End Sub
Function TotalCost(ByVal pizzaSlices As Double,
ByVal fries As Double, ByVal softDrinks As Double) As Double
Return (PIZZA_PRICE * pizzaSlices) + (FRIES_PRICE * fries) +
(DRINKS_PRICE * softDrinks)
End Function
End Class

You might also like