Scala version of repayment calculation