Solved

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);

}

}

}

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[][]={{mo

{payments[1][0]/1200,payme

//calculation for mortgage and output that shows payment amounts

double mortgage=(principal*(mortg

System.out.println("Mortga

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);

}

}

}

18 Comments

you are using mortgageRate and payments arrays as bidimensional arrays but they are not!

double monthMortgageRate[][]={{mo

{payments[1][0]/1200,payme

I've meant with my previous posting that you have declared the arrays as one dimensional

double mortgageRate[] = {.0535,.0550,.0575};

int payments[] = {84,180,360};

but you've used them az bidimendional.

So this has tobe the source for the error you've mentioned above.

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};

int lines = 0;

for(int i=0; i < 3; i++)

{

//calculation for mortgage and output that shows payment amounts

double mortgage=(principal*(mortg

System.out.println("Mortga

System.out.println((i+1) + "\t\t\t" + (mortgageRate[i]) +

"\t\t" + (payments[i]) +

"\t\t" + df.format(mortgage));

//new calculation for balance and interest

double newMonthlyInterest=princip

double newBalance=principal -(mortagage - newMonthlyInterest);

double mortgage = newBalance;

System.out.println("\n" +i+ "\t\t" + "\t\t\t" +string);

}

}

}

Your mortgageRate is no longer two dimensional array but you still use it as two dimensional array.

double newMonthlyInterest=princip

double newBalance=principal -(mortagage - newMonthlyInterest); // wrong spelling

double mortgage = newBalance; // duplication of mortgage...you already have mortgage before

System.out.println("\n" +i+ "\t\t" + "\t\t\t" +string); // where is the string is declared?

Is this what you want?

double newMonthlyInterest=princip

double newBalance=principal -(mortgage - newMonthlyInterest);

mortgage = newBalance;

System.out.println("\n" +i+ "\t\t" + "\t\t\t" +mortgage);

David

System.out.println("\n" +i+ "\t\t" + "\t\t\t" +mortgage);

David

David

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};

int lines = 0;

for(int i=0; i < 3; i++)

{

//calculation for mortgage and output that shows payment amounts

double mortgage=(principal*(mortg

System.out.println("Mortga

System.out.println((i+1) + "\t\t\t" + (mortgageRate[i]) +

"\t\t" + (payments[i]) +

"\t\t" + df.format(mortgage));

//new array for balance and interest

double newMonthlyInterest=princip

double newBalance=principal -(mortgage - newMonthlyInterest);

mortgage = newBalance;

System.out.println("\n" +i+ "\t\t" + "\t\t\t" +df.format(mortgage));

System.out.println("\n" +i+ "\t\t" + "\t\t\t" +df.format(mortgage));

}

}

}

//end of program

------=-

This below part calculates the mortgage for each of the 3 types and rates(at top of logic):

double mortgage=(principal*(mortg

System.out.println("Mortga

This part i think is supposed to calculate every payment for each of the above mortgage payments- list balance and interest paid until it is $0:

double newMonthlyInterest=princip

double newBalance=principal -(mortgage - newMonthlyInterest);

mortgage = newBalance;

When i compile it is succesfull but this is the output i get this below. It is like it stops after 1st payment:

Mortgage Mortgage Rate Payments Payment Amount

1 0.0535 84 $901.85

0 $209,798.15

Mortgage Mortgage Rate Payments Payment Amount

2 0.055 180 $916.71

1 $210,083.29

Mortgage Mortgage Rate Payments Payment Amount

3 0.0575 360 $958.33

2 $210,541.67

Can you provide me with the *real* number of output?

>>"Mortgage Mortgage Rate Payments Payment Amount

1 0.0535 84 $901.85

0 $209,798.15

Mortgage Mortgage Rate Payments Payment Amount

2 0.055 180 $916.71

1 $210,083.29

Mortgage Mortgage Rate Payments Payment Amount

3 0.0575 360 $958.33

2 $210,541.67"

Are these correct? If not, can you provide me with something like above but the correct version

David

David

By clicking you are agreeing to Experts Exchange's Terms of Use.

Title | # Comments | Views | Activity |
---|---|---|---|

format the code in java | 6 | 60 | |

hasOne challenge | 59 | 63 | |

noX challenge | 17 | 52 | |

Path of Workbook | 3 | 30 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**12** Experts available now in Live!