Total beginner
I am working on a project for school and I have it mostly done but there is one part I can't figure out. This is the assignment:
Modify the mortgage program for week 2 to display 3 mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.75%. Use an array to hold the three interest rates and an array for the three loan terms. Display the mortgage payment amount for each loan. Do not use a graphical user interface. Insert comments in the program to document the program.
I know, I think everyone in a Java I class has this assignment. The problem is that instead of giving me just values 7 years-5.35, 15 years-5.5, and 30 years-5.75, which is three statements I am getting all the interest rate for all the years-ex: 7 years-5.35, 5.5 and 5.75 and so on. Anyway this is my code-hope it is readable. Help please. :o
import java.text.NumberFormat;
public class MortgageCalculator2 {
public static void main(String args[]) {
//Declare all variables.
double payment;
double principal = 200000;
double[] rate = {5.35, 5.5, 5.75};
double monthlyRate;
int[] years = {7, 15, 30};
int months;
NumberFormat currency = NumberFormat.getCurrencyInstance(); /*This
is so payment can be converted to currency format*/
for (int y = 0; y < years.length; y++) {
for (int r = 0; r < rate.length; r++) {
monthlyRate = (rate[r] / 1200);
months = (years[y] * 12);
//Calculate monthly payment
payment = principal *(monthlyRate / (1 - Math.pow(1 + monthlyRate, - months)));
//Display loan and payment information
System.out.println("The borrowed amount is " + currency.format(principal) + ".");
System.out.println("The interest rate is " + rate[r] + "%.");
System.out.println("The term is " + years[y] + " years.");
System.out.println("The monthly payment is " + currency.format(payment) + ".");
System.out.println();
}
}
}
}
I know I am missing something but what???

