java
import java.text.DecimalFormat;
//
public class MortgagePayment
{
public void calc(double interest, double principle, int monthlypayments)
{
//Declare and construct variables
DecimalFormat decimalPlaces = new DecimalFormat(".00");
double monthlypayments, principle, interest, interestAmount, payment;
int amount, i, paymentsPerPage, lengthOfPause;
// Variable Declaration
int principal[] = {200000, 200000, 200000}; // Principal for each calculation
double interestRate[] = {5.35, 5.50, 5.75}; // Interest Rate for each interest rate
int totalYears[] = {7, 15, 30}; // Length in years for each loan
double monthlyInterest[] = {0, 0, 0}; // Monthly Interest
int totalMonths[] = {0, 0, 0}; // Number of Months
double monthlyPayment[] = {0, 0, 0}; // Monthly Payment
// Calculations Loop
for (int i = 0; i < 3; i++){
monthlyInterest[i] = interestRate[i] / (12 * 100);
totalMonths[i] = totalYears[i] * 12;
monthlyPayment[i] = principal[i] * (monthlyInterest[i] /
(1 - (Math.pow((1 + monthlyInterest[i]),(-totalMonths[i])))));
}
//Output to screen
System.out.println("Principle = $"+decimalPlaces.format(principle)); //The loan amount
System.out.println("Interest Rate ="+interest*100 +"%"); //The interest rate
System.out.print("Payment per Month = $"); //The monthly payment amount
System.out.println(decimalPlaces.format(payment));
System.out.println("********************");
System.out.println("********************");
for(i = 1; i <= 1; i++)
{
System.out.println("Payment " + i + ":");
System.out.println("----------");
System.out.println("Payment Amount: $ " + decimalPlaces.format(payment));
interestAmount = ((interest / 12) * principle);
System.out.println("Interest Amount: $ " + decimalPlaces.format(interestAmount));
// You also have to calculate interest and add that back in.
principle = (principle - payment) + interestAmount;
System.out.println("Loan Balance: $ " + decimalPlaces.format(principle));
System.out.println("----------");
System.out.println("");
if(((i - 1) % paymentsPerPage) == 0)
{
try{Thread.sleep(lengthOfPause * 1000);} //This is a pause function.
catch(InterruptedException ie){}
}
}
}
}
You tell us, does it work ? if not what is wrong with it ?
Oh and don't forget to use the code tags when posting codez