login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Collectiontypes invoices (Opgelost)

Offline Jimbo - 19/12/2009 16:12 (laatste wijziging 19/12/2009 16:14)
Avatar van JimboLid Ik heb vandaag weer een oefening bij rond het opmaken van een collectietype te maken.

Onderstaande is de oefening:
===============
'Creëer collectietype Invoice om onderstaande testen te doen slagen.
'Van een factuur ( Invoice ) kan je het aantal artikels opvragen, het totale bedrag opvragen en een artikel op een bepaalde positie opvragen. Men kan uiteraard ook een artikel en hoeveelheid van dit artikel toevoegen.


===============

  1. Class Article
  2. Private _Price As Decimal
  3. Public Property Price() As Decimal
  4. Get
  5. Price = _Price
  6. End Get
  7. Set(ByVal value As Decimal)
  8. _Price = value
  9. End Set
  10. End Property
  11. End Class
  12.  
  13. Module InvoiceTestFixture
  14. Sub Main()
  15. Dim invoice1 As New Invoice
  16. Console.WriteLine(invoice1.ArticleCount = 0) ' True
  17. Console.WriteLine(invoice1.GetTotal() = 0D) ' True
  18. '
  19. Dim article1 As New Article
  20. article1.Price = 100D
  21. invoice1.Add(article1, 5)
  22. Console.WriteLine(invoice1.ArticleCount = 1) ' True
  23. Console.WriteLine(invoice1(0) Is article1) ' True
  24. Console.WriteLine(invoice1.GetTotal() = 500D) ' True
  25. '
  26. Dim article2 As New Article
  27. article2.Price = 20D
  28. invoice1.Add(article2, 3)
  29. Console.WriteLine(invoice1.ArticleCount = 2) ' True
  30. Console.WriteLine(invoice1(0) Is article1) ' True
  31. Console.WriteLine(invoice1(1) Is article2) ' True
  32. Console.WriteLine(invoice1.GetTotal() = 560D) ' True
  33. '
  34. Console.ReadLine()
  35. End Sub
  36. End Module


Kan iemand hiermee verder helpen?
Alles zou uiteindelijk true moeten eindigen zoals in de comments is weergegeven.

1 antwoord

Gesponsorde links
Offline Ontani - 19/12/2009 17:31
Avatar van Ontani Gouden medailleGouden medailleGouden medailleGouden medaille

-1
  1. Public Class Invoice
  2. Inherits List(Of Article)
  3.  
  4. Dim _Pricing As New Dictionary(Of Article, Integer)
  5.  
  6. Public Function ArticleCount() As Integer
  7. Return Me.Count
  8. End Function
  9.  
  10. Public Function GetTotal() As Decimal
  11. Dim total As Decimal = 0
  12. For Each art As KeyValuePair(Of Article, Integer) In Me._Pricing
  13. total += art.Key.Price * art.Value
  14. Next
  15. Return total
  16. End Function
  17.  
  18. Public Overloads Sub Add(ByVal art As Article, ByVal number As Integer)
  19. Me.Add(art)
  20. Me._Pricing.Add(art, number)
  21. End Sub
  22.  
  23. End Class
Bedankt door: Jimbo
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.211s