This project makes use of concepts and statements that we have covered recently.
ID: 3688568 • Letter: T
Question
This project makes use of concepts and statements that we have covered recently. This program simulates a POS (Point of Sale) system for an Asian Restaurant. The customer chooses their Entrée (Main Dish) and optionally a Starter course and a beverage. The program will compute the order total. The program also keeps a running total of all orders which have been entered. Notice how the buttons and group boxes are enabled and disabled in order to control which features the user can use at any time. For example, until the user selects an Entrée, the Starter and Beverage choices are disabled. The Clear Order button unchecks the radio buttons and check boxes, deselects the beverage and clears the Cost of Order (Subtotal, Tax, Total) but DOES NOT clear the Running Total. In order to manage adding the selected beverage price to the total it is useful to use the technique in which a second list box off-screen is used to hold the matching prices. The following is how the interface looks.
Below is the code i have so far, im not sure how to do the return statments for the code,and also how to compute the totals for the running total and subtotal. Also the variables im claiming as double may not be right?
Public Class Form1
End Class
'A class level variable since we need its value to stay valid
Dim dblsubTotal As Double
'A user defined function to calculate the starter cost
Function starters() As Double
Dim DblsubTotal As Double
If chkeggroll.Checked = True Then
DblsubTotal = DblsubTotal + 1.5
End If
'Enter the statements for the other items
If chkspringroll.Checked = True Then
DblsubTotal = DblsubTotal + 2.0
?
End If
If chksoup.Checked = True Then
DblsubTotal = DblsubTotal + 2.5
End If
If chkcrabdelite.Checked = True Then
DblsubTotal = DblsubTotal + 2.5
End If
lblsubtotal.text = dblsubtotal.tostring("c")
Return dblsubtotal
?
End Function
'A user defined function to calculate the main dish cost
Function MaindishTotal() As Double
Dim dblsubTotal As Double
If radsweetandsourchicken.Checked = True Then
dblsubTotal = dblsubTotal + 8.0
ElseIf radbeefandpeapods.Checked = True Then
dblsubTotal = dblsubTotal + 8.5
ElseIf radcashewchicken.Checked = True Then
dblsubTotal = dblsubTotal + 8.0
ElseIf radshrimpfriedrice.Checked = True Then
dblsubTotal = dblsubTotal + 7.5
ElseIf radeggfooyong.Checked = True Then
dblsubTotal = dblsubTotal + 7.0
End If
?
End Function
Private Sub btncalculatetotals_Click(sender As System.Object, e As System.EventArgs)
End Sub
Private Sub btnaddnew_Click(sender As System.Object, e As System.EventArgs)
End Sub
Private Sub btnCleartotals_Click(sender As System.Object, e As System.EventArgs) Handles btnCleartotals.Click
Clear display labels, check boxes and radio buttons
lblordertotal.Text = ""
lbltax.Text = ""
lblsubtotal.Text = ""
?
chkeggroll.Checked = False
chksoup.Checked = False
chkspringroll.Checked = False
chkcrabdelite.Checked = False
radsweetandsourchicken.Checked = False
radbeefandpeapods.Checked = False
radcashewchicken.Checked = False
radshrimpfriedrice.Checked = False
radeggfooyong.Checked = False
lstPrices.SelectedIndex = -1
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Explanation / Answer
Your code is very confusing and incomplete. Still, I try to make sense of it and try to help you accordingly. First of all, in this function starters(), please keep a different name for your subtotal variable, it is creating confusion with your class level variable. Also set the subtotal text for running total accordingly.
'A user defined function to calculate the starter cost
Function starters() As Double
Dim starterSubTotal As Double
If chkeggroll.Checked = True Then
starterSubTotal = starterSubTotal + 1.5
End If
'Enter the statements for the other items
If chkspringroll.Checked = True Then
starterSubTotal = starterSubTotal + 2.0
End If
If chksoup.Checked = True Then
starterSubTotal = starterSubTotal + 2.5
End If
If chkcrabdelite.Checked = True Then
starterSubTotal = starterSubTotal + 2.5
End If
lblrunningsubtotal.Text = Convert.ToString(starterSubTotal + Convert.ToDouble(lblrunningsubtotal.Text))
lblrunningtax.text = Convert.ToString( 0.056 * Convert.ToDouble(lblrunningsubtotal.Text) + Convert.ToDouble(lblrunningtax.Text))
lblrunningtotal.text = Convert.ToString(Convert.ToDouble(lblrunningsubtotal.Text) + Convert.ToDouble(lblrunningtax.Text))
Return starterSubTotal
End Function
Similarly, do it for the function MaindishTotal()
'A user defined function to calculate the main dish cost
Function MaindishTotal() As Double
Dim mainDishSubTotal As Double
If radsweetandsourchicken.Checked = True Then
mainDishSubTotal = mainDishSubTotal + 8.0
ElseIf radbeefandpeapods.Checked = True Then
mainDishSubTotal = mainDishSubTotal + 8.5
ElseIf radcashewchicken.Checked = True Then
mainDishSubTotal = mainDishSubTotal + 8.0
ElseIf radshrimpfriedrice.Checked = True Then
mainDishSubTotal = mainDishSubTotal + 7.5
ElseIf radeggfooyong.Checked = True Then
mainDishSubTotal = mainDishSubTotal + 7.0
End If
lblrunningsubtotal.Text = System.Convert.ToString(mainDishSubTotal + System.Convert.ToDouble(lblrunningsubtotal.Text))
lblrunningtax.text = Convert.ToString( 0.056 * Convert.ToDouble(lblrunningsubtotal.Text) + Convert.ToDouble(lblrunningtax.Text))
lblrunningtotal.text = Convert.ToString(Convert.ToDouble(lblrunningsubtotal.Text) + Convert.ToDouble(lblrunningtax.Text))
return mainDishSubTotal
End Function
At last, write implementation for calculate totals button as follows:
Private Sub btncalculatetotals_Click(sender As System.Object, e As System.EventArgs)
lblsubtotal.Text = lblrunningsubtotal.Text
lbltax.Text = lblrunningtax.text
lblordertotal.Text = lblrunningtotal.Text
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.