# Loan repayment calculator

• October 14th, 2013, 04:53 AM
CruelCoin
Loan repayment calculator
Hi all.

I'm having some trouble with a Loan repayment Calculator.

It seems to be working fine, but it give me answers very different to that of online calculators.

Any tips greatly appreciated.

Thanks,

CC.

import javax.swing.JOptionPane;
public class Q1

{
public static void main (String [] args)
{
String interest = JOptionPane.showInputDialog("Please enter an interest rate");
double interestRateFirst = Double.parseDouble(interest);
double interestRate = interestRateFirst / 100;
String loan = JOptionPane.showInputDialog("Please enter a loan amount in Euro");
double loanAmount = Double.parseDouble(loan);
String length = JOptionPane.showInputDialog("Please enter the length of the loan in years");
double lengthOfLoan = Double.parseDouble(length);

double monthlyLoanRepayments = (loanAmount*interestRate)/(1-(1/(Math.pow((1+interestRate),(lengthOfLoan*12)))));

System.out.println("The monthly repayment amount is: " + monthlyLoanRepayments);

}
}

--- Update ---

Sorry,

Can a mod tag this as solved?

I just had to change the interest rate to monthly interest.

Cheers,

CC.
• October 14th, 2013, 05:01 AM
GregBrannon
Re: Loan repayment calculator
`double monthlyLoanRepayments = (loanAmount*interestRate)/(1-(1/(Math.pow((1+interestRate),(lengthOfLoan*12)))));`