0

> I am trying to code an assignment that calculates the

> payments for a mortgage of a loan amount using 3

> separate rates and term years. I have it working but

> it wants to calculate each loan 3 times with all

> three rates and with the years so instead of having

> the printout with 7 years, 15 years and 30 years I

> have each 3 times with the different interest rate.

> Any help is appreciated.

>

> Thanks

>

> Here is the code I have:

>

```
import java.io.*; // java input output package
import java.text.DecimalFormat;
class PaymentArray2
{
public static void main(String[] arguments)
{
double amount = 200000;
int[]term = {7, 15, 30};
double[] rate = {.0535, .055, .0575};
DecimalFormat twoDigits = new DecimalFormat("$000.00");
System.out.println("With a loan amount of " +twoDigits.format(amount));
for (int i = 0; i < term.length; i++)
{
for (int j = 0; j < rate.length; j++)
{
System.out.print("for " + term[i] + " years");
System.out.print("\tat a rate of " + rate[j]);
double payment = (amount*(rate[j]/12))/(1-(Math.pow(1/(1+(rate[j]/12)),(term[i]*12))));
System.out.println("\tThe monthly payment will be " + twoDigits.format(payment));
}
}
}
}
```