My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Loan
def initialize(rate, months, presentValue)
@rate = rate;
@months = months
@presentValue = presentValue
end

def rate
@rate
end

def months
@months
end

def presentValue
@presentValue
end

def to_s
"-- Rate #{@rate}-- Months #{@months}-- PresentValue #{@presentValue}"
end

def calculateMonthlyPayment
fPresentValue = presentValue.to_f
fRate = rate.to_f / 1200
fMonths = months.to_f


revisedRate = fRate + 1;
powRate = revisedRate**fMonths

left = powRate * fPresentValue
middle = fRate / (powRate - 1)

right = 1

payment = left * middle * right

(payment * 100).round.to_f / 100
end

def calculatePaymentSchedule
payment = self.calculateMonthlyPayment
balance = (presentValue * 100).to_f / 100
totalPrinciple = 0
totalInterest = 0

fRate = rate.to_f / 1200

i = 0
months.times do
i = i + 1
puts i.to_s
interest = ((balance * fRate) * 100).round.to_f / 100
principle = ((payment - interest) * 100).round.to_f / 100
if (balance < payment)
principle = balance
end
totalPrinciple += principle
totalInterest += interest

balance = balance - principle

puts "INTEREST: #{interest} PRINCIPLE: #{principle} BALANCE: #{balance}"
end
puts "TOTAL PRINCIPLE: #{totalPrinciple}"
puts "TOTAL INTEREST: #{totalInterest}"
payment
end

end

Change log

r54 by pragkirk on Apr 8, 2009   Diff
Initial Checkin
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1695 bytes, 72 lines

File properties

svn:executable
Powered by Google Project Hosting