not sure how this site works...

I'm stuck with a run error (Array out of bound exception 4)and can't figure it out, i'm new to the world of Java programming, so I'm hoping I'm not asking anything dump!

pasted my code here:

``````/* Purpose: To develop a program to accept multiple inputs from loan information on
three different loans(Loan Amount, Interest Rate and Loan Period). Calculate the
necessary elements such as the Months and Monthly payments and output the loan amount,
interest rate, period length and monthly payment.*/

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

public class mortgageIA4
{
public static void main(String[] args) throws IOException
{

//Declaring variables

String loan,interestRate,period;
double interest, payment;
int looq,q;
interest = 0.00;
payment =0.00;
q=0;
DecimalFormat decimalPlaces=new DecimalFormat("0.00");

//For accepting values from keyboard

//Array assignments

double interest1 [] = new double [3];
int term1 [] = new int[3];
double mPayment[] = new double[4];
double loan1 [] = new double[3];
//Start questions loop

for (looq = 0; looq<3; looq++)
{

//while (q<3)

//{
try
{

System.out.print("\n");
System.out.print("Please enter the loan amount for loan " + (looq + 1) + " \$:");
loan1[looq] = Double.parseDouble(loan);
}//close try
catch(Exception e)
{
System.out.println("Error in Data" +( "\n") + "Your input is invalid please enter valid number (Ex.200000)");//* added a missing +

}//close catch

try
{
System.out.print("Please enter the annual interest rate (Ex:5.0): ");

interest1 [looq] = Double.parseDouble(interestRate);
interest1[looq] = (interest1[looq]/100);
}
catch(Exception e)
{
System.out.println("Error in Data" +( "\n") + "Your input is invalid please enter valid number (Ex.200000)");//* added a missing +

}//close catch

try
{
System.out.print("Please enter the term of the loan in years: ");

//term = Double.parseDouble(period);
term1 [looq] = Integer.parseInt(period);

}//close try

catch(Exception e)
{
System.out.println("Error in Data! Must re-enter loan  " +(looq+1)+ " data" +( "\n")+  "Your input is invalid please enter valid number (Ex.2 or 2.5 or 200)");//****exception error message
}//close catch
q++; //*** increments loop counter

//}//close while expression

}//close for loop

//Create Monthly Payment calculation

mPayment[looq]=(loan1[looq]*((interest1[looq]/12)/(1-Math.pow((1+(interest1[looq]/12)),-(term1[looq]*12)))));

//Outputs Table
System.out.print("\n");
System.out.println("Principal\tInterest\tMonths\t\tPayment");

//set counter for print loop
for (looq=0; looq < 3 ; looq++ )
{
System.out.print("\n");
System.out.println((looq + 1) + "\t\$" + decimalPlaces.format(loan1[looq]) + "\t "
+ decimalPlaces.format(interest1[looq]*100) + "%" + "\t  " + term1[looq] + "\t\$"
+ decimalPlaces.format(mPayment[looq]));
System.out.print("\n");
//looq++;
}

}

}
``````

Edited by Dani: Formatting fixed

2
Contributors
1
2
Views
10 Years
Discussion Span
``````System.out.println(looq+" "+interest1.length);