home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.1 KB | 65 lines | [TEXT/ttxt] |
- --<<<
-
- class MortgagePayments (IndirectCollection)
- instance variables
- totalPayments -- a virtual instance variable
- presentValue -- a virtual instance variable
- instance methods
- method init self #rest args -> (
- apply nextMethod self targetCollection:(new SortedArray) args
- )
- method isAppropriateObject self addedObject -> (
- -- check that it is the right kind of object
- if not isAKindOf addedObject Pair do (
- format debug "not a pair\n" undefined @normal
- return false
- )
- if not isAKindOf addedObject[1] Date do (
- format debug "first element not a date\n" undefined @normal
- return false
- )
- if not isAKindOf addedObject[2] Number do (
- format debug "second element not a number\n" undefined @normal
- return false
- )
- return true
- )
- method objectAdded self addedKey addedObject -> (
- -- does nothing for now
- return true
- )
- method objectRemoved self objectRemoved -> (
- -- does nothing for now
- return true
- )
- end -- MortgagePayments
-
- method totalPaymentsGetter self {class MortgagePayments} -> (
- local sum := 0
- forEach self (x -> sum := sum + x[2]) undefined
- return sum
- )
- method getNetPresentValue self {class MortgagePayments} discountRate -> (
- local sum := 0
- local today := theCalendarClock.date
- forEach self (x -> sum := sum + presentValue x today discountRate) undefined
- return sum
- )
-
- function presentValue payment today discountRate -> (
- local conversion := (60 * 60 * 24 * 365.25)
- local y := (today as LargeInteger) / conversion
- local z := (payment[1] as LargeInteger) / conversion
- return (payment[2] * exp (negate(discountRate * (z - y))))
- )
-
-
- -- create an instance, and then add some data to it
- myPayments := new MortgagePayments
- add myPayments empty (new Pair values:#((new Date year:1996 month:@july),50000))
- add myPayments empty (new Pair values:#((new Date year:1997 month:@july),50000))
- add myPayments empty (new Pair values:#((new Date year:1998 month:@july),50000))
- add myPayments empty (new Pair values:#((new Date year:1999 month:@july),50000))
- add myPayments empty (new Pair values:#((new Date year:2000 month:@july),50000))
-
- -->>>