My favorites
▼
|
Sign in
kcode
Sample code projects
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
kata
/
ruby
/
v2
/
app
/
Loan.rb
r109
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
73
74
75
76
77
require 'Payment.rb'
require 'PaymentSchedule.rb'
class Loan
def initialize(rate, months, presentValue)
@rate = rate.to_f
@months = months.to_i
@presentValue = presentValue.to_f
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
totalPrinciple = 0
totalInterest = 0
fRate = rate.to_f / 1200
i = 0
schedule = PaymentSchedule.new
months.times do
i = i + 1
interest = ((balance * fRate) * 100).round.to_f / 100
principle = ((payment - interest) * 100).round.to_f / 100
if (balance < payment)
principle = (balance * 100).round.to_f / 100
end
totalPrinciple += principle
totalInterest += interest
balance = ((balance - principle) * 100).round.to_f / 100
pmt = Payment.new(i, principle, interest, balance)
schedule.addPayment(pmt)
# puts "INTEREST: #{pmt.interest} PRINCIPLE: #{pmt.principle} BALANCE: #{pmt.balance}"
end
schedule.setTotalPrinciple(totalPrinciple)
schedule.setTotalInterest(totalInterest)
schedule
end
end
Show details
Hide details
Change log
r54
by pragkirk on Apr 8, 2009
Diff
Initial Checkin
Go to:
/trunk/kata
/trunk/kata/ruby
/trunk/kata/ruby/intro.txt
/trunk/kata/ruby/v1
/trunk/kata/ruby/v1/app
/trunk/kata/ruby/v1/app/Input.rb
/trunk/kata/ruby/v1/app/Loan.rb
/trunk/kata/ruby/v1/runtest.bat
/trunk/kata/ruby/v1/test
...nk/kata/ruby/v1/test/LoanTest.rb
/trunk/kata/ruby/v1/v1.txt
/trunk/kata/ruby/v2
/trunk/kata/ruby/v2/app
/trunk/kata/ruby/v2/app/Input.rb
/trunk/kata/ruby/v2/app/Loan.rb
/trunk/kata/ruby/v2/app/Payment.rb
...a/ruby/v2/app/PaymentSchedule.rb
/trunk/kata/ruby/v2/readme.txt
/trunk/kata/ruby/v2/runtest.bat
/trunk/kata/ruby/v2/test
...nk/kata/ruby/v2/test/AllTests.rb
...nk/kata/ruby/v2/test/LoanTest.rb
...y/v2/test/PaymentScheduleTest.rb
/trunk/kata/ruby/v3
/trunk/kata/ruby/v3/app
/trunk/kata/ruby/v3/app/Input.rb
/trunk/kata/ruby/v3/app/Loan.rb
/trunk/kata/ruby/v3/app/Payment.rb
...a/ruby/v3/app/PaymentSchedule.rb
/trunk/kata/ruby/v3/rakefile.rb
/trunk/kata/ruby/v3/readme.txt
/trunk/kata/ruby/v3/runtest.bat
/trunk/kata/ruby/v3/test
...nk/kata/ruby/v3/test/AllTests.rb
...nk/kata/ruby/v3/test/LoanTest.rb
...y/v3/test/PaymentScheduleTest.rb
/trunk/kata/ruby/v3/trouble.txt
/trunk/kata/ruby/v4
/trunk/kata/ruby/v4/app
/trunk/kata/ruby/v4/app/Loan.rb
...nk/kata/ruby/v4/app/LoanEntry.rb
/trunk/kata/ruby/v4/app/Payment.rb
...a/ruby/v4/app/PaymentSchedule.rb
/trunk/kata/ruby/v4/app/Server.rb
/trunk/kata/ruby/v4/app/var
/trunk/kata/ruby/v4/app/var/www
...a/ruby/v4/app/var/www/index.html
/trunk/kata/ruby/v4/coverageout
.../v4/coverageout/app-Loan_rb.html
...eout/app-PaymentSchedule_rb.html
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1925 bytes, 77 lines
View raw file
File properties
svn:executable
Powered by
Google Project Hosting