home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Bank / loan.vb < prev    next >
Encoding:
Text File  |  2000-06-23  |  2.4 KB  |  110 lines

  1. '===========================================================================
  2. '  File:      Loan.vb
  3. '
  4. '  Summary:   This is the one file that implements the loan methods
  5. '
  6. '----------------------------------------------------------------------------
  7. '  This file is part of the Microsoft NGWS Samples.
  8. '
  9. '  Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  10. '============================================================================
  11. Option Strict Off
  12.  
  13.  
  14. Namespace Loan
  15. Public Class BankLoan
  16. Inherits Account
  17.  
  18. Private OrigPrin As Double
  19. Private OrigRate As Double
  20. Private OrigTerm As Integer
  21. Private pmt As Double
  22.  
  23. Public Function GetPrincipal() As Double
  24.         GetPrincipal = OrigPrin
  25. End Function
  26.  
  27. Public Sub SetPrincipal(ByVal p As Double)
  28.         OrigPrin = p
  29. End Sub
  30.  
  31. Public Function GetRate() As Double
  32.         GetRate = OrigRate
  33. End Function
  34.  
  35. Public Sub SetRate(ByVal r As Double)
  36.         OrigRate = r
  37. End Sub
  38.  
  39. Public Function GetTerm() As Integer
  40.         GetTerm = OrigTerm
  41. End Function
  42.  
  43. Public Sub SetTerm(ByVal t As Integer)
  44.         OrigTerm = t
  45. End Sub
  46.  
  47. Public Function GetPayment() As Double
  48.         GetPayment = pmt
  49. End Function
  50.  
  51. Public Sub SetPayment(ByVal p As Double)
  52.         pmt = p
  53. End Sub
  54.  
  55. Public Function CalcPmt(ByVal prin As Double, ByVal rate As Double, ByVal term As Double) As Double
  56.  
  57.           CalcPmt = prin * (rate / (1 - Power((1 + rate), -term)))
  58.    
  59. End Function
  60.  
  61. Public Function OpenAccount(ByVal p As Double, ByVal r As Double, ByVal t As Integer) As Integer
  62.         OrigPrin = p
  63.         OrigRate = r
  64.         OrigTerm = t
  65.  
  66.         pmt = CalcPmt(p, r, t)
  67.  
  68.         SetBalance (OrigPrin)
  69.  
  70.         OpenAccount = 1
  71. End Function
  72.  
  73. Public Function MakePayment(ByVal pmt As Double) As Integer
  74.         Dim interest As Double
  75.         Dim principal As Double
  76.  
  77.         interest = GetBalance() * OrigRate
  78.         principal = pmt - interest
  79.  
  80.         MakePayment = Debit(principal)
  81.  
  82. End Function
  83.  
  84.  
  85. Private Function Power(ByVal x As Double, ByVal y As Integer) As Double
  86.         Dim invert As Boolean
  87.         Dim p As Double
  88.         Dim i As Integer
  89.  
  90.         invert = False
  91.  
  92.         p = 1#
  93.  
  94.         If (y < 0) Then
  95.                 y = -y
  96.                 invert = True
  97.         End If
  98.  
  99.         For i = 1 To y
  100.                 p = p * x
  101.         Next
  102.  
  103.         If (invert) Then p = (1 / p)
  104.  
  105.         Power = p
  106.  
  107. End Function
  108.  
  109. End Class
  110. End Namespace