what i am trying to do is this Display the mortgage payment amount and then list the loan balance and interest paid for each payment over the term of the loan. If the list would scroll off the screen, use loops to display a partial list, hesitate, and then display more of the list. below is the code i have .. i have the loan balance correct (i think) but i don't have the interest paid correct BUT when i run it the interest paid populates the same amount over and over. So can someone please help me with my interest paid issue, and the loops to display partially,hesitate and then more of the list?
*/
package mortgagecalc;
/* A program written in Java that will calculate and display the monthly payment amount to a $200,000.00 loan over a 30 year term at a 5.75‰ interest rate. */
import java.lang.Math.*;
/* Program uses the Math class to perform mathematical functions. */
public class Main //Beginning
{
public static void main(String[] args) //tells the program what to do
{
/* P = principal, the initial amount of the loan
I = the annual interest rate (from 1 to 100 percent)
L = length, the length (in years) of the loan, or at least the length over which the loan is amortized.
J = monthly interest in decimal form = I / (12 x 100)
N = number of months over which loan is amortized = L x 12
M = the monthly payment
M = P * ( J / (1 - (1 + J) ** -N))
Above are the definitions and terms to create an equation to calculate the mortgage payment.
[url]http://www.hughchou.org/calc/formula.html[/url]
*/
double dblmonthlypayment; // payment
double dblprincipal=200000; // Amount of principal
int intyears=30; // Number of years in loan
int intnumberOfMonthsAmortize; // Number of Months
double dblinterest=5.75; // Interest Rate
double dblmonthlyInterest; // Monthly Interest Rate
dblmonthlyInterest = dblinterest/(12*100); //J monthly interest
intnumberOfMonthsAmortize = intyears*12; //N number of months
dblmonthlypayment = dblprincipal*(dblmonthlyInterest / (1 - Math.pow((1 + dblmonthlyInterest), -intnumberOfMonthsAmortize))); // Forumla M = P * ( J / (1 - (1 + J) ** -N))
System.out.println(); //spacing
System.out.println("Principal of the loan = $200,000");// displays as is
System.out.println("Loan length = 30 years"); // displays as is
System.out.println("Loan Interest = 5.75%"); // displays as is
System.out.println("Monthly payment = $ " +dblmonthlypayment); // displays as is and monthly payment result based on the calculation
System.out.println(); // spacing
//Declares and builds three new variables
double loanBalance = 0;
double interestPaid = 0;
int lineCount = 20;
loanBalance = dblprincipal - dblmonthlypayment;
//Starts loop statement,and declares formula for loan balance and interest paid
while (loanBalance > 0) {
//Displays the loan balance and interest paid
System.out.println("The loan balance is: $" + loanBalance);
System.out.println("The interest paid on the loan is: $" + interestPaid);
loanBalance = loanBalance - dblmonthlypayment;
interestPaid = dblmonthlypayment * dblmonthlyInterest;
//Pauses screen
if (lineCount > 0) {
lineCount--;
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
}
}
}
//Stops loop statement
if (loanBalance <= 0) {
}
}
}
Ok when i run it this is what i'm getting.
run:
Principal of the loan = $200,000
Loan length = 30 years
Loan Interest = 5.75%
Monthly payment = $ 1167.1457128870982
The loan balance is: $198832.8542871129
The interest paid on the loan is: $0.0
The loan balance is: $197665.70857422578
The interest paid on the loan is: $5.592573207584012
The loan balance is: $196498.56286133867
The interest paid on the loan is: $5.592573207584012
The loan balance is: $195331.41714845155
The interest paid on the loan is: $5.592573207584012
The loan balance is: $194164.27143556444
The interest paid on the loan is: $5.592573207584012
The loan balance is: $192997.12572267733
The interest paid on the loan is: $5.592573207584012
The loan balance is: $191829.98000979022
The interest paid on the loan is: $5.592573207584012
The loan balance is: $190662.8342969031
The interest paid on the loan is: $5.592573207584012
The loan balance is: $189495.688584016
The interest paid on the loan is: $5.592573207584012
The loan balance is: $188328.54287112888
The interest paid on the loan is: $5.592573207584012
The loan balance is: $187161.39715824177
The interest paid on the loan is: $5.592573207584012
The loan balance is: $185994.25144535466
The interest paid on the loan is: $5.592573207584012
The loan balance is: $184827.10573246755
The interest paid on the loan is: $5.592573207584012
The loan balance is: $183659.96001958044
The interest paid on the loan is: $5.592573207584012
The loan balance is: $182492.81430669333
The interest paid on the loan is: $5.592573207584012
The loan balance is: $181325.66859380621
The interest paid on the loan is: $5.592573207584012
The loan balance is: $180158.5228809191
The interest paid on the loan is: $5.592573207584012
The loan balance is: $178991.377168032
The interest paid on the loan is: $5.592573207584012
BUILD STOPPED (total time: 27 seconds)