package loancalculation;
public class LoanCalculation
{
// Main method
public static void main(String[] args)
{
double annualInterestRate;
int numOfYears;
double loanAmount;
// Enter monthly interest rate
System.out.println(
"Enter yearly interest rate, for example 8.25: ");
annualInterestRate = MyInput.readDouble();
// Obtain monthly interest rate
double monthlyInterestRate = annualInterestRate/1200;
// Enter number of years
System.out.println(
"Enter number of years as an integer, for example 5: ");
numOfYears = MyInput.readInt();
// Enter loan amount
System.out.println("Enter loan amount, for example 120000.95: ");
loanAmount = MyInput.readDouble();
// Calculate payment
double monthlyPayment = loanAmount*monthlyInterestRate/
(1 - (Math.pow(1/(1 + monthlyInterestRate), numOfYears*12)));
double totalPayment = monthlyPayment*numOfYears*12;
// Display results
System.out.println("The monthly payment is " + monthlyPayment);
System.out.println("The total payment is " + totalPayment);
// Pause
System.out.println("Press Ctrl+C to close this window ...");
MyInput.readInt();
}
}

While pursuing a Computer Science degree, I founded DaniWeb.com, an online community for developers and IT professionals. I coded the backend platform from the ground up and I also do all of the advertising sales and SEO. I'm a super-geeky programmer with a passion for Internet marketing.

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.