I am in a class and am trying to get this project done. I get the code to compile but it is giving me a out of bounds error. Here is the assignment.
Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:

•7 year at 5.35%
•15 year at 5.5%
•30 year at 5.75%
Use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen.
Here is the code.\

``````/*
Week5 Assignment
Programer: CButler
Date March 19,2010
FileName: PaymentCalculatorwk5.java
*/

import java.text.DecimalFormat;

public class PaymentCalculatorwk5
{
public static void main (String [] args)
{
//Calculate monthly payment of loan
double principle = 200000;			          // Principle Loan Amount
double [] AnnualInterest = {5.35, 5.5, 5.75};	                         // Annual Interest Amaount
int [] Months = {84, 180, 360};				        // Number of Months
double MonthlyInterest= 0;       // Monthly interest
double MonthlyPayment = 0;                            // Monthly Payment
double CurrentMonthlyInterest = 0;                   //Current Monthly Interest
double PaidPerMonth = 0;                            //Amount paid per month
double NewBalance = 0;                             //monthly Balance
//Using Decimal format to display money
DecimalFormat money = new DecimalFormat ("\$0,000.00");
//Create Loop for the arrays monthly payment
for(int i=0; i <=2; i++)
{
//Calculation for monthly monthly payment
MonthlyInterest = AnnualInterest[i]/(12*100);
MonthlyPayment = principle * (MonthlyInterest / (1 - (Math.pow(1 + MonthlyInterest, -Months[i]))));
}
//display the headers
System.out.println("\n\nNumber of\tMonthly\t\tInterest\tCurrent");
System.out.println("Months\t\tPayment\t\tPayment\t\tBalance");
System.out.println("----------\t----------\t----------\t----------");

//Loop to Calculate the Term of the loan
for(int i = 1; i <= Months [i]; i++)
{
CurrentMonthlyInterest = principle * MonthlyInterest;
PaidPerMonth = MonthlyPayment - CurrentMonthlyInterest;
NewBalance = principle - PaidPerMonth;
principle = NewBalance;

System.out.println("[" + i +"]: \t\t" + money.format (MonthlyPayment) + "\t\t" + money.format (CurrentMonthlyInterest) + "\t\t" + money.format (NewBalance));

//Condition to hit enter after 20 entries
if(i % 25 == 0)
{
System.out.print("Press [ENTER] to continue ...");
try
{
System.in.read();
System.in.skip (System.in.available());
}
catch (Exception e){e.printStackTrace();}

}
}
}
}``````
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by BestJewSinceJC

The error message would be nice.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.