I cannot seem to get the array to work and display the second and third loans, only the first one displays. Here is what I need to clarify the situation. I added the array to the program and it only works for the first loan. Can someone point me in the right direction.

Loan 1 15,000 12% 60 $333.67 $5,020.20 $20,020.20
Loan 2 15,000 10% 48 $xxx.xx $x.xxx $xx,xxx.xx
Loan 3 15,000 8% 36 $xxx.xx $x,xxx $xx,xxx.xx

// MortgageCalculatorProgram.java
// program to calculate mortgage
// Erik Voigt
// 05/16/10


import java.text.DecimalFormat;
import java.io.*; 
import java.util.Arrays;


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

  // define variables, payments, principle, interest, rate, and loan information

        double monthlyPayment;
		double principal;
		double interestRateYears;
		double interestRateMonths;
		int termYears;
		int termMonths;
		int linecount;

// will display balance, interest paid, principle, interest payments

		double balance;
		double interestPaid;
		double principalPaid;
		double monthlyInterestPayment;
		double monthlyPrincipalPayment;


// assign values to each item

        principal = 15000;
       	interestRateYears = .012;
       	interestRateMonths = (interestRateYears / 12) / 100;
        termYears = 3;
        termMonths = (termYears * 12);
        monthlyInterestPayment = 0;
        monthlyPrincipalPayment = 0;
        balance = principal;

// display 10 lines of results at one time

        linecount = 10;

// will only display two decimal places out

        java.text.DecimalFormat dec = new java.text.DecimalFormat(",###.00");

// hard coded information per assignment

        System.out.println("\n\n\t*** Mortgage Calculator ***\n\n" +
        				"\nLoan Amount: \t$" + dec.format(principal) +
       					"\nInterest Rate: \t" + interestRateYears +"%" +
        				"\nTerm (Years): \t" + termYears);

// will calculate monthly mortgage payment

       	monthlyPayment = (principal * interestRateMonths) /
                       	(1 - Math.pow(1 + interestRateMonths, - termMonths));

// Print the information

      	System.out.println("\n\nBased on the information, "  +
                        "the monthly payment amount will be: " +
                        "$" + dec.format(monthlyPayment));

// calculation

        monthlyInterestPayment = (balance * interestRateMonths);
        monthlyPrincipalPayment = (monthlyPayment - monthlyInterestPayment);

// provides columns

        System.out.println("\n\n\nMonths\t\tPrincipal\tInterest\tBalance");
        System.out.println("Remaining\tPayment\t\tPayment\t\tRemaining");
        System.out.println("---------  \t---------  \t---------  \t---------");

// start the while loop
       while (termMonths > 0)

{

// information to be displayed

       System.out.println(termMonths + "\t\t$" + dec.format(monthlyPrincipalPayment) +
                         "\t\t$" + dec.format(monthlyInterestPayment) +
                         "\t\t$" + dec.format(balance - monthlyPrincipalPayment));

// decrement of  months
       termMonths--;

// calculate interest and principal payments on the loan

       monthlyInterestPayment = (balance * interestRateMonths);
       monthlyPrincipalPayment = (monthlyPayment - monthlyInterestPayment);
       balance = (balance - monthlyPrincipalPayment);

// this will cause the results to pause
        if(linecount == 10)
		{

        linecount = 0;
        try
		{
        Thread.sleep(2000);

        }
        catch (InterruptedException e)
        {
          }
        }
// end if
        else
        {
        linecount++;
        }
// end else
        }
// end while
        }
// end main
}
	
class MortgageArray1

{
   
	public static void main(String[] arguments)

{


	double amount = 15000;
	int[]term = {36, 48, 60};
	double[] rate = {.012, .010, .008};
	DecimalFormat twoDigits = new DecimalFormat("$000.00");

	System.out.println("With the loan amount of  " +twoDigits.format
	(amount));

	for (int i = 0; i < rate.length; i++)
	{

	System.out.print("for " + term[i] + " years");
	System.out.print("\tat a rate of " + rate[i]);
	double payment = (amount*(rate[i]/12))/(1-(Math.pow(1/(1+(rate
	[i]/12)),(term[i]*12))));

	System.out.println("\tThe monthly payment will be " +
	twoDigits.format(payment));

	}
  }
}

Why do you have 2 programs in there (2 mains)? I don't see any Loan array in your code. can you mark the lines where you are printing the loan array? It is a little difficult to read.

I was using this as the array, but I think that I did it wrong. I removed the second main string, forgot I left it in, what should I do next?

class MortgageArray1
{
   	
{
	double amount = 15000;
	int[]term = {36, 48, 60};
	double[] rate = {.012, .010, .008};
	DecimalFormat twoDigits = new DecimalFormat("$000.00");

	System.out.println("With the loan amount of  " +twoDigits.format
	(amount));

	for (int i = 0; i < rate.length; i++)
	{

	System.out.print("for " + term[i] + " years");
	System.out.print("\tat a rate of " + rate[i]);
	double payment = (amount*(rate[i]/12))/(1-(Math.pow(1/(1+(rate
	[i]/12)),(term[i]*12))));

	System.out.println("\tThe monthly payment will be " +
	twoDigits.format(payment));

	}
  }

Now your class doesn't have any functions? How will this code ever execute? I'm sorry, either you have no clue what you are doing, or you are not able to express it well. This code, MortgageArray1, with a main function should probably work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.