Solved
loops/arrays
Posted on 2006-05-01
Hi. I am trying to modify my original program with an array of 3 mortgage amounts: $200000: 7yr at 5.35, 15 yr at 5.5 and 30 yr at 5.75. I have to show the mortgage payment and then the balance and interest paid. when i declare the new double with the array i get an error that " java:28: array required, but double found". Do i have something wrong?
import java.io.*;
import java.text.DecimalFormat;
class Mortgage
{
public static void main(String arguments[])
{
/*Declaring Program Variables*/
double interestRate = 0.0575;//*Interest rate
double principal = 200000.00;//*Amount of Loan
double monthlyInterest = interestRate/12; //*Monthly interest
int periods = 360; //* 30 yrs @12 months each year is 360 months
double balance = principal;
double monthlyPrincipal;
DecimalFormat df = new DecimalFormat("$#,###.00");
//Create new decimal format object that has the format required for this program
double mortgageRate[] = {.0535,.0550,.0575};
int payments[] = {84,180,360};
double monthMortgageRate[][]={{mortgageRate[0][0]*12,mortgageRate[0][1]*12,mortgageRate[0][2]*12},
{payments[1][0]/1200,payments[1][1]/1200,payments[1][2]/1200}};
//calculation for mortgage and output that shows payment amounts
double mortgage=(principal*(mortgageRate[i]/12)/(1-(Math.pow(1/(1+mortgageRate[i]/12), (payments[i]*12)))));
System.out.println("Mortgage\t\tMortgage Rate\tPayments\tPayment Amount");
System.out.println((i+1) + "\t\t\t" + (mortgageRate[i]) +
"\t\t" + (payments[i]) +
"\t\t" + df.format(mortgage));
int lines = 0;
for(int i=0; i < 3; i++)
{
//new array for balance and interest
double monthlyInterest=principal * monthMortgageRate[1][i];
double newBalance=principal -(mortagage - monthlyInterest);
double mortgage = newBalance;
System.out.println("\n" +i+ "\t\t" + "\t\t\t" +string);
}
}
}