C# Create a console app that can be used to calculate the total amount due for p
ID: 3724625 • Letter: C
Question
C#
Create a console app that can be used to calculate the total amount due for puchases. Allow any number of items to be entered - you'll need to enter these in a loop until a certain condition is met. Determine the total due including sales tax (8.25) and shipping. sales tax is charged against the total puchases and shipping is based on the number of items purchased.
Fewer than 3 items $3.50
3-6 items $5.00
7-10 items $7.00
11-15 items $9.00
More than 15 items $10.00
Display an itemized summary containing the total puchase charge, number of items purchased, sales tax amount, shipping charge, and grand total.
Explanation / Answer
Public Class Form1
Dim OrderLines As List(Of OrderLine) = New List(Of OrderLine)
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim intQuantity As Integer
If Not Integer.TryParse(txtQuantity.Text, intQuantity) Then
MsgBox("Error in entering quantity")
Exit Sub
End If
Dim decPrice As Decimal
If Not Decimal.TryParse(txtPrice.Text, decPrice) Then
MsgBox("Error in entering price")
Exit Sub
End If
Dim decTotal As Decimal = decPrice * CDec(intQuantity)
txtTotal.Text = decTotal.ToString
OrderLines.Add(New OrderLine(txtItem.Text, intQuantity, decPrice))
ListUpdate()
End Sub
Private Sub ListUpdate()
ListBox1.Items.Clear()
For Each O As OrderLine In OrderLines
ListBox1.Items.Add(O.ToString)
Next
End Sub
Private Structure OrderLine
Dim LineItem As String
Dim LineQuantity As Integer
Dim LinePrice As Decimal
Public Sub New(ByVal Item As String, ByVal Quantity As Integer, ByVal Price As Decimal)
LineItem = Item
LineQuantity = Quantity
LinePrice = Price
End Sub
Public Overloads Function ToString() As String
Return LineItem & " " & LinePrice.ToString _
& " " & LineQuantity.ToString _
& " " & (LinePrice * CDec(LineQuantity)).ToString
End Function
End Structure
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.