Java Programing
I am trying to modify this mortage program I wrote to display 3
mortgage loans for 7 years ar 5.35%, 15 years at 5.5% and 30 years at
5.75% by using an array for the different loan and displaying the
mortage payment for each loan. These are suppose to loop. Need help
here is my program I worte: I canot get it to loop.
*/
import /*static*/ java.lang.Math.*;
import java.text.*;
class MortgageV4 //Begin class definition for class "Betty"
{
public static void main(String[]args) //Begin "MainMortage" method
{
//Declare & initalize variable
double loanPrincipal = 200000;
int loanPeriods = 360;
double loanAnnualRate = 0.0575;
double loanMonthlyRate = loanAnnualRate/12;
double loanPayment = 0;
double monthlyInterest;
double monthlyPrincipal;
int r;
double [][] arr575 = new double [400][3];
double [][] arr535 = new double [400][3];
double [][] arr55 = new double[400][3];
//Setup money formatting
//start from here
loanPeriods = 360;
loanAnnualRate = 0.0575;
loanMonthlyRate = loanAnnualRate/12;
DecimalFormat moneyFormat = new DecimalFormat(
"$###,###.00" );
//Calculate loan payment based on formula described in header
loanPayment = loanPrincipal*((loanMonthlyRate) / (1 -
Math.pow(1 + loanMonthlyRate,-1 * loanPeriods)));
//Print basic summary output
System.out.println("\nPOS-406 Assignment 3 - Loan
Calculator");
System.out.println("by Betty Jones");
System.out.println("----------------------------------------\n");
System.out.println("Loan Principal (Dollars): " +
moneyFormat.format(loanPrincipal));
System.out.println("Loan Periods (Months): " + loanPeriods);
System.out.println("Interest Rate (Annual): " +
loanAnnualRate*100 + "%");
System.out.println("Loan Payment (Monthly): " +
moneyFormat.format(loanPayment));
//2 Second Pause
//try {Thread.sleep(2000);}
//catch (InterruptedException e) { e.printStackTrace();}
r=0;
//Initialize loop to cycle through loan periods
for (loanPeriods=loanPeriods ; loanPeriods > 0 ; )
{
//Print header information
//System.out.println("\n\nPmt#\tPrincipal Due\tMonthly
Int\tMonthly Principal");
//System.out.println("----------------------------------------------------------------");
//Initialize loop to print only 30 entries at a time
for (int loopCount=0; loopCount < 30; loopCount++);
{
monthlyInterest =loanPayment*loanPrincipal *
loanMonthlyRate;
//Calculate monthly interest
monthlyPrincipal =
loanPaymentInterest-monthlyInterest;
//Calculate monthly principal
loanPrincipal = loanPrincipal + monthlyInterest -
loanPayment; //Calculate new principal by adding interest
snd deducting payment
loanPeriods--; //Decrement loanPeriods counter
System.out.println(360-loanPeriods + "\t" +
moneyFormat.format(
loanPrincipal) + "\t" + moneyFormat.format(monthlyInterest) +
"\t\t" + moneyFormat.format(monthlyPrincipal)); //Print monthly
detail
}
//2 Second Pause
// try {Thread.sleep(2000);}
// catch (InterruptedException e) {
e.printStackTrace();}
arr575[r][0] = loanPrincipal;
arr575[r][1] = monthlyInterest;
arr575[r][2] = monthlyPrincipal;
r++;
}
for (int r1 = 0; r1<360; r1++)
{
System.out.println(r1+1 + "\t");
for (int c1 = 0; c1<3; c1++)
{
System.out.println(moneyFormat.format(arr575[r1][c1]) + "\t");
}
System.out.println();
}
}
//End "main" method
}
//End class definition for class "Betty"