Arrays and Mortgage Calculator Issues

Good Afternoon,

Here is my code to calculated a loan amount among different percentage rates and terms.  
import java.io.IOException;

public class GutierrezMortgages {

    //Method to Calculate Mortgage using the principal amount, the interest, and the term
    static  int[] loanTerm = {360,180,84}; //*30 years, 15 years, 7 years
    static  double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)
    static  double loanAmount = 200000; //*$200,000 Loan

    public static double calculateMortgage (double loanAmount, double loanInterest, int loanTerm) {
       double myMortgage = (loanAmount*loanInterest/12)/(1-Math.pow(1+loanInterest/12, -loanTerm));
       return myMortgage;
    }

    //Method to display the calculated mortgage
    public static void displayTheMortgages()  {
       System.out.println();
       System.out.printf("\t\tLoan Amount: $%.2f\n", loanAmount);
       
       for (int i = 0; i < loanTerm.length; i++) {
       System.out.printf("\t\tTerm: %d Years", loanTerm [i] / 12);
       System.out.println();
       System.out.printf("\t\tInterest Rate: %.2f%%", loanInterest[i] * 100);
       System.out.println();
       System.out.printf("\t\tThe monthly payment amount is $%.2f", calculateMortgage (loanAmount, loanInterest[i], loanTerm[i]));
       System.out.println();
       }
    }

    public static void main(String[] args){
       displayTheMortgages();
    }
}

Open in new window


This executes what I want but the problem is that I need to place this variables into
the main () method with argument of type arrays and pass the arrays from main because our instructor does not want these variables in another method other than the main () method.

I am still new to Java and my mind is numb with all this code.  Any help would be great!

PapaDragonXAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

PapaDragonXAuthor Commented:
The variables that I need to place in the main() method are:

  //Method to Calculate Mortgage using the principal amount, the interest, and the term
    static  int[] loanTerm = {360,180,84}; //*30 years, 15 years, 7 years
    static  double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)
    static  double loanAmount = 200000; //*$200,000 Loan 

Open in new window


Here is my revised code that has 9 errors:
/*Joshua Gutierrez
	PRG 420
	Week 4
	Individual Assignment
	3/27/3011
*/
package joshua;

import java.io.IOException;

public class GutierrezMortgages {

    
    public static double calculateMortgage (double loanAmount, double loanInterest, double loanTerm) {
       double myMortgage = (loanAmount*loanInterest/12)/(1-Math.pow(1+loanInterest/12, -loanTerm));
       return myMortgage;
    }

    //Method to display the calculated mortgage
    public void displayTheMortgages(double myCalculatedMortgage)  {
       System.out.println();
       System.out.printf("\t\tLoan Amount: $%.2f\n", loanAmount);
       
       for (int i = 0; i < loanTerm.length; i++) {
       System.out.printf("\t\tTerm: %d Years", loanTerm [i] / 12);
       System.out.println();
       System.out.printf("\t\tInterest Rate: %.2f%%", loanInterest[i] * 100);
       System.out.println();
       System.out.printf("\t\tThe monthly payment amount is $%.2f", calculateMortgage (loanAmount, loanInterest[i], loanTerm[i]));
       System.out.println();
       }
    }

    public static void main(String[] args){

		//Method to Calculate Mortgage using the principal amount, the interest, and the term
                  double loanTerm[] = {360,180,84}; //*30 years, 15 years, 7 years
                  double loanInterest[] = {.0575, .0550, .0535}; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)
                  double loanAmount = 200000; //*$200,000 Loan


	
                 // Create an instance of the class

		GutierrezMortgages myInstance = new GutierrezMortgages ();

                // Use my the class instance and the dot notation to call the method that calculates the mortgage

		double myMortgage = myInstance.calculateMortgage (loanAmount, loanInterest, loanTerm);

                // Display the calculated mortgage

		myInstance.displayTheMortgage(myMortgage);
       
    }
}  

Open in new window

0
CEHJCommented:
Try
import java.io.IOException;


public class GutierrezMortgages {
    //Method to Calculate Mortgage using the principal amount, the interest, and the term
    public static double calculateMortgage(double loanAmount,
        double loanInterest, int loanTerm) {
        double myMortgage = ((loanAmount * loanInterest) / 12) / (1 -
            Math.pow(1 + (loanInterest / 12), -loanTerm));

        return myMortgage;
    }

    //Method to display the calculated mortgage
    public static void displayTheMortgages(int[] loanTerm,
        double[] loanInterest, double loanAmount) {
        System.out.println();
        System.out.printf("\t\tLoan Amount: $%.2f\n", loanAmount);

        for (int i = 0; i < loanTerm.length; i++) {
            System.out.printf("\t\tTerm: %d Years", loanTerm[i] / 12);
            System.out.println();
            System.out.printf("\t\tInterest Rate: %.2f%%", loanInterest[i] * 100);
            System.out.println();
            System.out.printf("\t\tThe monthly payment amount is $%.2f",
                calculateMortgage(loanAmount, loanInterest[i], loanTerm[i]));
            System.out.println();
        }
    }

    public static void main(String[] args) {
        int[] loanTerm = { 360, 180, 84 }; //*30 years, 15 years, 7 years
        double[] loanInterest = { .0575, .0550, .0535 }; //*5.75% interest rate(ir), 5.50% (ir), 5.35% (ir)
        double loanAmount = 200000; //*$200,000 Loan
        displayTheMortgages(loanTerm, loanInterest, loanAmount);
    }
}

Open in new window

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
PapaDragonXAuthor Commented:
Awesome,

I totally messed up the revision and noticed that all I had to do was define the arguments within the "displayTheMortgages[loanTerm, loanInterest, loanAmount" and moving the brackets in the main() method.  Thanks for lending another set of eyes to this!
0
PapaDragonXAuthor Commented:
Outstanding!  Thanks for clarifying!
0
CEHJCommented:
:)
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.