Can't figure out my error..

I have to write a Mortgage Program that will show interest paid over 30 years.

I am getting the following error when running the program.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

at MortgageProject.main(MortgageProject.java:33)

Thanks in advanced for your help.

/*

* MortgageProject.java

* This program is to display the mortgage payment from hard coded numbers from arrays

* without accepting any input from users. Then it is to list the balance

* and interest paid for each payment or the entire loan.

*/

import java.text.DecimalFormat;//needed to set the decimal point place

import javax.swing.JOptionPane;//needed to make the program pause

import java.io.*;

import java.util.Date;

class MortgageProject

{

publicstaticvoid main(String[]args)throws Exception

{

Date currentDate =new Date();//Date constructor

int[] MonthPayment ={30};//declares how many years

double Monthly = 0;//delcares the variable for the mortgage payment

double Amount = 200000;//declares how much the loan is for

double[] MonthInt ={5.75};//declares the interest rate

double PaidInt;//paid interest monthly

double OutStand;//monthly balance

int MonthTerm;//number of payments

char enter;

DecimalFormat TwoDec =new DecimalFormat("0.00");//decimal format for ouput

for (int i=0; i<3;i++)//loop for each array

{

MonthTerm=MonthPayment[i]*12;//monthterm will now equal the number of payments

MonthInt[i]=MonthInt[i]/100/12;//monthint will now equal the MONTHLY interest rate

//following determines the mortgage payment

Monthly = (Amount*Math.pow((1+MonthInt[i]),MonthTerm)*MonthInt[i])/

(Math.pow((1+MonthInt[i]),MonthTerm)-1);

System.out.println("\t" + currentDate);

System.out.println();

System.out.println("\n\tTerm of Loan:"+MonthPayment[i]+" yrs");

System.out.println("\n\tInterest Rate of Loan:"+TwoDec.format(MonthInt[i]*100*12)+"%");

System.out.println("\n\tMonthly Payment:$"+TwoDec.format(Monthly));

System.out.println();

OutStand=Amount;

for (int m=1;m<=MonthTerm;m++)//loop to display all monthly data

{

if (m%11==0)//loop to display 11 lines before requesting the enter key

{

System.out.println("\nPress the Enter Key to Continue");//tells user to hit enter key to continue

enter=(char)System.in.read();

System.in.read();

}

PaidInt=OutStand*MonthInt[i];//calculates the amount paid to interest

OutStand=OutStand-Monthly+PaidInt;//adjust the outstanding balance for each month

System.out.println(m+"\t"+"$"+TwoDec.format(PaidInt)+"\t\t"+"$"+TwoDec.format(OutStand));

}

}

}

}

[5023 byte] By [azquadza] at [2007-11-27 10:19:18]
# 1

http://forum.java.sun.com/thread.jspa?threadID=5193957

DON'T DOUBLE POST!

You just waste people's time.

floundera at 2007-7-28 16:56:51 > top of Java-index,Java Essentials,New To Java...
# 2

I know, I am sorry. I am new to this forum. I will not do this again. Once again I am sorry.

azquadza at 2007-7-28 16:56:51 > top of Java-index,Java Essentials,New To Java...
# 3

it runs fine on my pc...

import java.text.DecimalFormat; //needed to set the decimal point place

import javax.swing.JOptionPane; //needed to make the program pause

import java.io.*;

import java.util.Date;

public class MortgageProject {

public static void main(String[]args) throws Exception

{

Date currentDate = new Date(); //Date constructor

int[] MonthPayment = {30}; //declares how many years

double Monthly = 0; //delcares the variable for the mortgage payment

double Amount = 200000; //declares how much the loan is for

double[] MonthInt = {5.75};//declares the interest rate

double PaidInt; //paid interest monthly

double OutStand;//monthly balance

int MonthTerm; //number of payments

char enter;

DecimalFormat TwoDec = new DecimalFormat("0.00");//decimal format for ouput

for (int i=0; i<3;i++) //loop for each array

{

MonthTerm=MonthPayment[i]*12; //monthterm will now equal the number of payments

MonthInt[i]=MonthInt[i]/100/12; //monthint will now equal the MONTHLY interest rate

//following determines the mortgage payment

Monthly = (Amount*Math.pow((1+MonthInt[i]),MonthTerm)*MonthInt[i])/

(Math.pow((1+MonthInt[i]),MonthTerm)-1);

System.out.println("\t" + currentDate);

System.out.println();

System.out.println("\n\tTerm of Loan:"+MonthPayment[i]+" yrs");

System.out.println("\n\tInterest Rate of Loan:"+TwoDec.format(MonthInt[i]*100*12)+"%");

System.out.println("\n\tMonthly Payment:$"+TwoDec.format(Monthly));

System.out.println();

OutStand=Amount;

for (int m=1;m<=MonthTerm;m++)//loop to display all monthly data

{

if (m%11==0)//loop to display 11 lines before requesting the enter key

{

System.out.println("\nPress the Enter Key to Continue");//tells user to hit enter key to continue

enter=(char)System.in.read();

System.in.read();

}

PaidInt=OutStand*MonthInt[i]; //calculates the amount paid to interest

OutStand=OutStand-Monthly+PaidInt; //adjust the outstanding balance for each month

System.out.println(m+"\t"+"$"+TwoDec.format(PaidInt)+"\t\t"+"$"+TwoDec.format(OutStand));

}

}

}

}

output:

Term of Loan:30 yrs

Interest Rate of Loan:5.75%

Monthly Payment:$1167.15

1$958.33$199791.19

2$957.33$199581.37

3$956.33$199370.56

4$955.32$199158.73

5$954.30$198945.88

6$953.28$198732.02

7$952.26$198517.13

8$951.23$198301.22

9$950.19$198084.26

10$949.15$197866.27

Yannixa at 2007-7-28 16:56:51 > top of Java-index,Java Essentials,New To Java...
# 4

Yannix

The point of reply 1 was to alert people to the fact that this person has posted the same question twice and is getting

help in the other thread. Therefore not to waste your time posting a reply. Or others time in reading your reply when the

problem may already been solved. If you want to contribute do so in the other thread.

NO MORE REPLIES!

floundera at 2007-7-28 16:56:51 > top of Java-index,Java Essentials,New To Java...