I would like to add loops to the following code that I have written so that it will display all of the information down to the last month. Can you help?
import java.text.DecimalFormat; //Required for format output
public class MortgagePaymentCalculator
{
//Hard code the amount=400,000, the term=30 years, and the interest rate=4.75%
static double MortgageAmount = 400000;
//400,000 is the amount of the mortgage
static int TermYears = 30;
//30 is the length of time that the amount is to be payed back
static double InterestRate = 4.75;
//4.75 is the percentage of interest to be paid monthly
static double MonthlyPayment;
//Total monthly payment
static double MonthlyInterest;
static int Months;
static double MonthlyInterestRate;
static int Payment;
static double Balance;
static double MonthlyInterestPaid;
static double Principle;
static int PaymentNumber;
static double LastPrinciple;
static int Delay;
//Main
public static void main(String[] args)
{
DecimalFormat Money = new DecimalFormat("$0,000.00")
;
//Monthly Payment Calculations
Months = (TermYears * 12);
//Calculates the total number of months to pay mortgage (360)
MonthlyInterestRate = (InterestRate *.01);
//Calculates the rate to a decimal format
MonthlyInterest = (MonthlyInterestRate/12);
//Calculates the amount of monthly interest
Balance = (MortgageAmount-MonthlyPay
ment);
Principle = (MonthlyPayment-MonthlyInt
erestPaid)
;
//Calculates monthly payment
MonthlyPayment = MortgageAmount*(MonthlyInt
erest*Math
.pow(1+Mon
thlyIntere
st,Months)
)/(Math.po
w(1+Monthl
yInterest,
Months) -1);
//Calculates the monthly payment
MonthlyInterestPaid = MonthlyInterest*Balance;
//Calculates the monthly interest paid
Balance = MortgageAmount - MonthlyPayment;
//Calculates the Balance
Principle = MonthlyPayment - MonthlyInterestPaid;
//Monthly Mortgage Payment Calculator Heading
System.out.println("//////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
///");
System.out.println(" Monthly Mortgage Payment Calculator");
System.out.println("//////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
///");
System.out.println("------
----------
----------
----------
----------
----------
----------
----------
---");
System.out.println();
//data produced from calculations
System.out.println("Total Mortgage Financed: "+ Money.format(MortgageAmoun
t));
System.out.println();
System.out.println("Total Mortgage Term: "+ TermYears);
System.out.println();
System.out.println("Intere
st Rate: "+ InterestRate + "%");
System.out.println();
System.out.println("Monthl
y Payment At Given Interest Rate: " + Money.format(MonthlyPaymen
t));
System.out.println("------
----------
----------
----------
----------
----------
----------
----------
---");
System.out.println();
//requesting the payment amount to be calculated
System.out.println("Paymen
t #1");
System.out.println();
System.out.println("Paymen
t Amount: " + Money.format(MonthlyPaymen
t));
System.out.println("Intere
st Paid: " + Money.format(MonthlyIntere
stPaid));
System.out.println("Princi
ple: " + Money.format(Principle));
System.out.println("Loan Balance: " + Money.format(Balance));
System.out.println();
System.out.println("------
----------
----------
----------
----------
----------
----------
----------
---");
System.out.println();
}
//Amortization
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
Method: getAmortization
Description: This method is established to calculate the "interest paid for each
over the term of the loan".
parameters: double Principle, double MonthlyPayment, double Balance
return: void
@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
*/
public static void Amortization (double Principle, double MonthlyPayment, double Balance)
{
DecimalFormat Money = new DecimalFormat("$0,000.00")
;
PaymentNumber = 1;
//Monthly Payment Calculations
Months = (TermYears * 12);
//Calculates the total number of months to pay mortgage (360)
MonthlyInterestRate = (InterestRate *.01);
//Calculates the rate to a decimal format
MonthlyInterest = (MonthlyInterestRate/12);
//Calculates the amount of monthly interest
Balance = (MortgageAmount-MonthlyPay
ment);
//Calculates the remaining balance
Principle = (MonthlyPayment-MonthlyInt
erestPaid)
;
LastPrinciple = (Principle);
Delay = 5000;
//Calculates monthly payment
MonthlyPayment = MortgageAmount*(MonthlyInt
erest*Math
.pow(1+Mon
thlyIntere
st,Months)
)/(Math.po
w(1+Monthl
yInterest,
Months) -1);
//Calculates the monthly payment
MonthlyInterestPaid = MonthlyInterest*Balance;
//Calculates the monthly interest paid
Balance = MortgageAmount - MonthlyPayment;
//Calculates the Balance
Principle = MonthlyPayment - MonthlyInterestPaid;
System.out.println();
System.out.println("Paymen
t Number: " + PaymentNumber);
System.out.println("Paymen
t Amount: " + Money.format(MonthlyPaymen
t));
System.out.println("Intere
st Paid: " + Money.format(MonthlyIntere
stPaid));
System.out.println("Princi
ple: " + Money.format(LastPrinciple
));
System.out.println("Loan Balance: " + Money.format(Balance));
System.out.println();
System.out.println("------
----------
----------
----------
----------
----------
----------
----------
---");
System.out.println();
}//End Payment Calculations
}//End MortgagePaymentCalulator