//Classes
import javax.swing.*;
import java.text.*;
public class MortgageCalculatorcr3
{
public static void main (String[] args)
{
//Variables
double[] interest = new double[4];
double[] principle = new double[4];
double[] monthlyPayments = new double[4];
double[] payment = new double[4];
double[] interestAmount = new double[4];
int paymentsPerPage,
lengthOfPause,
maxPayments;
//Variables for loan 1
interest[1] = 0.0535; // interest rate
principle[1] = 200000; // principle
monthlyPayments[1] = 84; // amount of monthly payments
//Variables for loan 2
interest[2] = 0.055; // interest rate
principle[2] = 200000; // principle
monthlyPayments[2] = 180; // amount of monthly payments
//Variables for loan 3
interest[3] = 0.0575; // interest rate
principle[3] = 200000; // principle
monthlyPayments[3] = 360; // amount of monthly payments
DecimalFormat decimalPlaces = new DecimalFormat("0.00"); //how the output is displayed
//Formulas for each loan 1-3
payment[1] = principle[1] * ((interest[1] / 12.0) / (1 - Math.pow((1 + (interest[1] / 12.0)), -monthlyPayments[1])));
payment[2] = principle[2] * ((interest[2] / 12.0) / (1 - Math.pow((1 + (interest[2] / 12.0)), -monthlyPayments[2])));
payment[3] = principle[3] * ((interest[3] / 12.0) / (1 - Math.pow((1 + (interest[3] / 12.0)), -monthlyPayments[3])));
String paymentOutput;
int pageCount = 0;
{
//Calculate payments for loans 1-3
interestAmount[1] = ((interest[1] / 12) * principle[1]);
principle[1] = (principle[1] - payment[1]) + interestAmount[1];
interestAmount[2] = ((interest[2] / 12) * principle[2]);
principle[2] = (principle[2] - payment[2]) + interestAmount[2];
interestAmount[3] = ((interest[3] / 12) * principle[3]);
principle[3] = (principle[3] - payment[3]) + interestAmount[3];
//new output for change request #2
System.out.println("");
System.out.println("");
System.out.println(" Loan 1 Loan 2 Loan3");
System.out.println("--------------------------------------------");
paymentOutput = " Amount: $ ";
{
paymentOutput = paymentOutput + padMe(decimalPlaces.format(payment[1]), 9) + " ";
}
{
paymentOutput = paymentOutput + " ";
}
{
paymentOutput = paymentOutput + padMe(decimalPlaces.format(payment[2]), 9) + " ";
}
{
paymentOutput = paymentOutput + " ";
}
{
paymentOutput = paymentOutput + padMe(decimalPlaces.format(payment[3]), 9);
}
System.out.println(paymentOutput);
System.out.println("Interest: $ " + padMe(NoneIfZero(decimalPlaces.format(interestAmount[1])), 9) + " " + padMe(NoneIfZero(decimalPlaces.format(interestAmount[2])), 9) + " " + padMe(NoneIfZero(decimalPlaces.format(interestAmount[3])), 9));
System.out.println(" Balance: $ " + padMe(NoneIfZero(decimalPlaces.format(principle[1])), 9) + " " + padMe(NoneIfZero(decimalPlaces.format(principle[2])), 9) + " " + padMe(NoneIfZero(decimalPlaces.format(principle[3])), 9));
System.out.println("--------------------------------------------");
{
pageCount = 0;
}
}
System.out.println("");
System.out.println("");
}
public static String padMe(String padValue, int padSize)
{
String returnValue = padValue;
for(int i = 0; i < (padSize - padValue.length()); i++)
{
returnValue = " " + returnValue;
}
return returnValue;
}
public static String NoneIfZero(String strValue)
{
double value = Double.parseDouble(strValue);
String returnValue;
if(value <= 0)
{
returnValue = " ";
}
else
{
returnValue = Double.toString(value);
}
return returnValue;
}
}
EDIT: CODE TAGS
This post has been edited by PennyBoki: 09 September 2007 - 12:13 PM

New Topic/Question
Reply




MultiQuote






|