Hello
I am a programmer student and for school I am building a small program. I got a collection Class Counters with two members: GetCount and GetCapacity. GetCount is the amount of counters in the collection Counters. GetCapacity is the total amount counters that the collection class can contain. Of course when the max amount is obtained, then should GetCapacity *=2. Now this my code:
Who can help? Thx.
I am a programmer student and for school I am building a small program. I got a collection Class Counters with two members: GetCount and GetCapacity. GetCount is the amount of counters in the collection Counters. GetCapacity is the total amount counters that the collection class can contain. Of course when the max amount is obtained, then should GetCapacity *=2. Now this my code:
VB.NET:
Class Counter
Private m_Value As Integer
Public ReadOnly Property Value() As Integer
Get
Value = m_Value
End Get
End Property
Public Sub Raise()
m_Value += 1
End Sub
End Class
Class Counters
'Geeft weer hoeveel counters in de Collectie counter kunnen zitten. Standaard is dit 16.
'Indien het aantal counters in de collectie gelijk is de (maximale) hoeveelheid counters in de collectie de wordt _
'de maximale hoeveelheid verdubbeld.
Private m_Capacity As Integer
Public Function GetCapacity() As Integer
If m_Capacity = m_Count Then
m_Capacity *= 2
Else : m_Capacity = 16
End If
GetCapacity = m_Capacity
End Function
'een indexer voor de counters
Private m_Items As Counter()
Default Public ReadOnly Property Item(ByVal index As Integer) As Counter
Get
Item = m_Items(index)
End Get
End Property
'geeft het aantal aangemaakte counters weer.
Private m_Count As Integer
Public Function GetCount() As Integer
GetCount = m_Count
End Function
'een add procedure om een counter toe te voegen in de collectie Counters
Public Sub Add(ByRef counter As Counter)
ReDim Preserve m_Items(GetCount())
m_Items(GetCount()) = counter
m_Count += 1
End Sub
Public Function GetTotal() As Integer
For Each item As Counter In m_Items
GetTotal += item.Value
Next
End Function
End Class
Module Module1
Sub Main()
Dim counter1 As New Counter
counter1.Raise()
Dim counter2 As New Counter
counter2.Raise()
counter2.Raise()
Dim counter3 As New Counter
counter3.Raise()
counter3.Raise()
counter3.Raise()
'
Console.WriteLine("De waarde van counter1 is : " & counter1.Value) 'voor indienen, verwijder deze lijn
Console.WriteLine("De waarde van counter2 is : " & counter2.Value) 'voor indienen, verwijder deze lijn
Console.WriteLine("De waarde van counter3 is : " & counter3.Value) 'voor indienen, verwijder deze lijn
'
'
Dim counters1 As New Counters
Console.WriteLine("De waarde van GetCount is : " & counters1.GetCount) 'voor indienen, verwijder deze lijn
Console.WriteLine("De waarde van GetCapacity is : " & counters1.GetCapacity) 'voor indienen, verwijder deze lijn
Console.WriteLine(counters1.GetCapacity() = 16) ' GetCapacity() of Capacity
Console.WriteLine(counters1.GetCount() = 0) ' GetCount() of Count
Console.WriteLine(counters1.GetTotal() = 0)
'Console.WriteLine(counters1.Contains(counter1) = False)
'Console.WriteLine(counters1.IndexOf(counter1) = -1)
''
'counters1.Add(counter1)
'counters1.Add(counter2)
'Console.WriteLine(counters1.GetCapacity() = 16) ' GetCapacity() of Capacity
'Console.WriteLine(counters1.GetCount() = 2) ' GetCount() of Count
'Console.WriteLine(counters1.GetTotal() = 3) ' counter1.Value + counter2.Value
'Console.WriteLine(counters1.Contains(counter1) = True)
'Console.WriteLine(counters1.Contains(counter3) = False)
'Console.WriteLine(counters1.IndexOf(counter2) = 1)
'Console.WriteLine(counters1.IndexOf(counter3) = -1)
'Console.WriteLine(counters1.Item(0) Is counter1)
'Console.WriteLine(counters1(1) Is counter2)
''
'counters1.TrimToSize()
'Console.WriteLine(counters1.GetCapacity() = 2) ' GetCapacity() of Capacity
'Console.WriteLine(counters1.GetCount() = 2) ' GetCount() of Count
''
'counters1.Add(counter3)
'counters1.Add(counter1)
'Console.WriteLine(counters1.GetCount() = 4) ' GetCount() of Count
'Console.WriteLine(counters1.GetTotal() = 7)
''
'counters1.RemoveAll(counter1)
'Console.WriteLine(counters1.GetCapacity() = 4) ' GetCapacity() of Capacity
'Console.WriteLine(counters1.GetCount() = 2) ' GetCount() of Count
'Console.WriteLine(counters1.GetTotal() = 5) ' GetCount() of Count
'Console.WriteLine(counters1.Contains(counter1) = False)
''
'counters1.RemoveAt(0)
'Console.WriteLine(counters1.GetCapacity() = 4) ' GetCapacity() of Capacity
'Console.WriteLine(counters1.GetCount() = 1) ' GetCount() of Count
'Console.WriteLine(counters1.Contains(counter2) = False)
'
Console.ReadLine()
End Sub
End Module