how to use method with multi-dimensional array.

Hi expert,

I'm trying to write a multi-dimensional array to calculate and display the monthly payments for $200,000 mortgage for 7 years at 5.35%, 15 years at 5.5% and 30 years at 5.75%.  It will also display
the loan balance and interest paid for each payment over the term of the loans.  However, I'm getting the following errors:

 ']' expected
    public static double calPayment(double monthsMonthlyRate[1][i], double monthsMonthlyRate[0][i], double mortgage) {
                                                                ^
 ')' expected
}
^
2 errors


Here's the program:

import java.math.*;
import java.text.*;
import java.util.*;

public class MortgageMulti {
    public static void main(String[] arguments) {

        double mortgage = 200000.00;
       double [][] yearsAnnualRate = {{7, 15, 30}, {5.35, 5.5, 5.75}};
       double monthsMonthlyRate = {{yearsAnnualRate[0][0]*12, yearsAnnualRate[0][1]*12, yearsAnnualRate[0][2]*12}, { yearsAnnualRate[1][0]/1200, yearsAnnualRate[1][1] / 1200, yearsAnnualRate[1][2] / 1200}};

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

              //Call the method
             double payment = calPayment(monthsMonthlyRate[1][i], monthsMonthlyRate[0][i], mortgage);

      // Display the monthly payment
      System.out.println("\nMortgage Amount \tTerm \t\tRate \t\tMonthly Payment");
      System.out.println("$200,000 \t\t" + yearsAnnualRate[0][i] + " years\t" + yearAnnualRate[1][i] + "%\t\t" + s);

       
      System.out.println("\nMonth # \tInterest for the Month \t\tLoan Balance");
      
                // Call the method
             interestBalanceList(mortgage, monthsMonthlyRate[1][i],monthsMonthlyRate[0][i], payment);
            }
    }

    // Utility method to calculate the monthly mortgage payment
    public static double calPayment(double monthsMonthlyRate[1][i], double monthsMonthlyRate[0][i], double mortgage) {

        // Calculate the monthlyPayment
        double monthlyPayment = (monthsMonthlyRate[1][i] + monthsMonthlyRate[1][i] / (Math.pow((1 + monthsMonthlyRate[1][i]), monthsMonthlyRate[0][i]) - 1)) * mortgage;

        return monthlyPayment;
          }

         // Utility method to list the interest paid and loan balance
      public static void interestBalanceList(double mortgage, double monthsMonthlyRate[1][i], double monthsMonthlyRate[0][i], double payment) {

            // Use the for loop to display the list
            for (int i = 1; i < (monthsMonthlyRate[0][i] + 1); i++) {

            // Pause the list
      System.out.println("Hit the 'ENTER' key to exit.");                                     try { System.in.read(); } catch (Exception e) {}
            // Calculate the monthlyInterest
            double monthlyInterest = mortgage * monthsMonthlyRate[1][i];

            // Calculate the loanBlance
            double loanBalance = mortgage - (payment - monthlyInterest);

            // Set the value of mortgageAmount to the value of loanBalance
            mortgage = loanBalance;

            // Formate the monthlyInterest into U.S. currency
            NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US);
            String str = n.format(monthlyInterest);

            // Formate the loanBalance into U.S. currency
            NumberFormat num = NumberFormat.getCurrencyInstance(Locale.US);
            String string = num.format(loanBalance);

            // Display the month #, interest paid and loan balance
            System.out.println("\n " + i + "\t\t " + str + "\t\t\t" + string);

            }
      }
}

Does anyone know what I'm doing wrong here?  Thanks.
LVL 1
dailydream04Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
Hi dailydream04,
>     public static double calPayment(double monthsMonthlyRate[1][i],   double monthsMonthlyRate[0][i], double mortgage) { ....}

should be:
 public static double calPayment(double param1,   double param2, double mortgage)

and inside this function replace each monthsMonthlyRate[1][i] with param1 and double monthsMonthlyRate[0][i] with param2
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petmagdyCommented:
also:
 >>      double monthsMonthlyRate = {{yearsAnnualRate[0][0]*12, yearsAnnualRate[0][1]*12, yearsAnnualRate[0][2]*12}, { yearsAnnualRate[1][0]/1200, yearsAnnualRate[1][1] / 1200, yearsAnnualRate[1][2] / 1200}};

should be:

       double[][] monthsMonthlyRate = {{yearsAnnualRate[0][0]*12, yearsAnnualRate[0][1]*12, yearsAnnualRate[0][2]*12}, { yearsAnnualRate[1][0]/1200, yearsAnnualRate[1][1] / 1200, yearsAnnualRate[1][2] / 1200}};

0
dailydream04Author Commented:
Hi petmagdy,

That makes perfect sense.  I don't know why I didn't think about it earlier.
Thanks for correcting double[][] too.  I realized it when I tried to compile it.  
Thanks you again for helping me to understand the multi-dimensional arrays.

:)
0
petmagdyCommented:
welcome any time :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.