I need to use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen. I have the mortgage payment amount for each loan. I NEED help with listing the loan balance and interest paid for each payment over the term of the loan.
CODE
public class MortgageCalculator4 {
/*
* - The main method.
*/
public static void main(String args[]) {
/*
* Sets the amount of the mortgage for the calculation of the
* loan.
*/
double amount = 200000;
/*
* Define the matrices to store information of the loans. They
* store the term (in years) and the interest rate of each loan.
*/
int term[] = { 7, 15, 30 };
double interestRate[] = { 5.35, 5.5, 5.75 };
/*
* Print the amount of the Mortgage.
*/
System.out.println(String
.format("Amount of the Mortgage: %.2f", amount));
/*
* Defines a format string to print information about each
* loan. Here we declare a variable to store the calculated monthly
* payment. This two variables, "fmt" and "monthlyPayment" are used
* inside the for loop.
*/
String fmt = "\t[Loan %d] Term: %2d year(s) Interest Rate: %6.2f%% Monthly Payment: $%6.2f";
double monthlyPayment;
/*
* The "for loop" to process the arrays.
*/
for (int i = 0; i < term.length; i++) {
/*
* - Calculates the monthly payment of the loan
*/
monthlyPayment = calculateMonthlyPayment(amount, interestRate[i],
term[i]);
/*
* Prints the informations gathered, using the format
* string "fmt".
*/
System.out.println(String.format(fmt, i + 1, term[i],
interestRate[i], monthlyPayment));
}
}
/*
* The calculateMonthlyPayment method.
*
*/
public static double calculateMonthlyPayment(double amount,
double interestRate, int term) {
//
// The formula has a principal, P, interest rate, r,
// and number of monthly payments, m.
//
// The down payment is included in P.
//
// P ( r / 12 )
// -------------------------
// (1 - pow( 1 + r / 12, -m ) )
//
double p = amount;
double r = interestRate / 100.00 / 12.00;
int n = (term * 12);
double num = p * r;
double den = (1 - Math.pow(1 + r, -n));
return den != 0 ? num / den : 0;
}
}
Can anyone help me??