Need Help with Assignment

Hi everyone, I am in a Java class and need help with my assignment. I am a little lost (well totally lost) ;). I am trying to create a mortgage calculator that will loop through three different loan terms (7 year at 5.35%, 15 year at 5.5%, and 30 year at 5.75%). I need to display an amortization table that will show principle, interest, monthly payment, and balance for each month of the loan term. My code is below - ant assistance would be much appreciated.


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

public class Mortgage3 {

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


double[][] payment={{200000, 84, .0535, 0.0},{200000, 180, .055, 0.0}, {200000, 360, .0575, 0.0}}; //starts the array


DecimalFormat decimal=new DecimalFormat ("#,##0.00"); //allows for the outcome to have 2 decimal points - barrowed from tony



for (int i=0; i <payment.length; i++){ //sets the loop

double loanAmount = payment[i][0]; //priniple amount
double interestAmount = payment[i][2]; //interest amount on loan
double loanTerms=payment[i][1]; //define the number of months for the loan
double interestMonthly=payment[i][2]/12; //calcualtes the interest amount monthly
double interestPower=Math.pow(interestMonthly +1, loanTerms); //calcualtes compounded interest
double interestCompound=interestMonthly * (interestPower)/(interestPower - 1); //determine increment of interest
double monthlyPayment=loanAmount*interestCompound; //this is the Prinicple[(interestMonthly)^360]/[(interestMonthly-1)]


//displays monthly payment for each term loan and interest
System.out.println();
System.out.println("************ McBride Financial Mortgage Calculator ******************");


//buffer below allows for payments/interest to be stored allowing user input to show the info in increments (ie. hitting any key to continue)
BufferedReader payments = new BufferedReader(new InputStreamReader(System.in));
payments.readLine();

//prints payment/interest/balance
System.out.println("Months----Payment---------Principal---------Interest----------Balance");

double principleAmount = 0.00; //amount of remaining principle
double interestAmountMonthly = 0.00; //monthly interest amount
double loanBalance = loanAmount; //sets loan balance equal to loan amount
double paymentMonthly = 0;//sets monthly payment to zero
int monthNumber = 0; //sets the loop to zero
int counter = 0; //sets the loop to zero


// calculates monthly paymeny / interest / principle - calculation taken from programmersheaven.com
interestAmountMonthly = (loanBalance * interestMonthly);
principleAmount = (loanBalance - interestAmountMonthly);
paymentMonthly = (principleAmount + interestAmountMonthly);

//creates the loop to display monthly principle/interest/loan balance 20 lines at a time
monthNumber++;

for ( monthNumber = 1; monthNumber <= 361; monthNumber++ ) {

//calculates the amortization table
interestAmountMonthly = (loanBalance * interestMonthly);
principleAmount = (monthlyPayment - interestAmountMonthly);
paymentMonthly = (principleAmount + interestAmountMonthly);
loanBalance = (loanBalance - principleAmount);


// displays the prinicple/interest/remaining balance in columns using tabs
System.out.println( monthNumber + " $" + decimal.format(monthlyPayment) +" $"+ decimal.format(payment[i][1]) +" $"+ decimal.format(interestAmountMonthly) +" $"+ decimal.format(loanBalance));


counter++; //sets loop for numnber of lines displayed

if (counter==20){ //only displays 20 lines at a time
System.out.print("
Press ENTER to continue:");
byte[] buffer = new byte[20]; //line taken from programmersheaven.com
System.in.read(buffer);
counter = 0;
System.out.println("Months----Payment---------Principal---------Interest----------Balance");


}//closes the if statement
}//closes the for loop
}//close of array loop
}//Close of Main
}//close of class Mortgage2

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion