Public Class CartItem Public ID As String Public Name As String Public Price As Double Public Count As Integer Public Sub New() ID = "-1" Name = "" Price = 0 Count = 0 End Sub End Class Public Class ShoppingCart Public Items As New Hashtable Public Sub New() Items.Clear() End Sub 'Add an item to the Shopping Cart Public Function Add(ByVal c As CartItem) As Boolean Dim tmpItem As CartItem If c.Name <> "" And c.Count > 0 Then tmpItem = Items(c.Name) If Not tmpItem Is Nothing Then tmpItem.Count += c.Count Else Items.Add(c.Name, c) End If Return True Else Return False End If End Function 'Modify an object quantity 'If quantity is zero the item is removed Public Function Modify(ByVal c As CartItem) As Boolean Dim tmpItem As CartItem If c.Name <> "" Then tmpItem = Items(c.Name) If Not tmpItem Is Nothing Then If tmpItem.Count > 0 Then tmpItem.Count = c.Count Else Items.Remove(c.Name) End If Return True Else Return False End If Else Return False End If End Function 'Empty the Shopping Cart Public Sub Empty() Items.Clear() End Sub 'calculate an object total price (items*price) Public Function ItemTotal(ByVal itemName As String) As Double Dim tmpItem As CartItem If itemName <> "" Then tmpItem = Items(itemName) If Not tmpItem Is Nothing Then Return tmpItem.Count * tmpItem.Price Else Return 0.0 End If Else Return 0.0 End If End Function 'Calculate the total price to pay Public Function Total() As Double Dim totale As Double = 0.0 For Each k As String In Items.Keys Dim ci As CartItem = Items(k) totale += ci.Price * ci.Count Next Return totale End Function End Class