My program is complete and compiles very nicely. I am on an extremely beginner level and understand some things but most of the things I do, I simply know that I am supposed to do them but do not exactly understand the why nor can I put things into laman's terms to understand them better. Here is my program and I am asking for just brief explanations for better understanding of my program. I will put ??? by things I hope someone can better explain. Thanks a million !!
import java.io.*;
import java.lang.Math.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale; // Do I even need this or would java.lang.math be fine without this line ???
public class Mortgages
{
public static void main(String[] args)
{
DecimalFormat twoDigits = new DecimalFormat("$###,###.00
");
double mortgage = 200000.00;
double[][] yearsYearlyRate = //Multiplies term by interest rate
{
{ 7, 15, 30 },
{ 5.35, 5.5, 5.75 }
};
double[][] monthsMonthlyRt =
{
{
yearsYearlyRate[0][0] * 12, yearsYearlyRate[0][1] * 12,
yearsYearlyRate[0][2] * 12 // Provide brief description please
},
{
// ????? I understand the above but need some clarification of the (1200)
yearsYearlyRate[1][0] / 1200, yearsYearlyRate[1][1] / 1200,
yearsYearlyRate[1][2] / 1200
}
};
for (int i = 0; i < 3; i++) // brief descriotion please of what this means
{
// ??? Please help here
double payment = calPayment(monthsMonthlyRt
[1][i], monthsMonthlyRt[0][i], mortgage);
System.out.println("\nMort
gage Amount \tTerm \t\tRate \t\tMonthly Payment");
System.out.println("$200,0
00 \t\t" + yearsYearlyRate[0][i] + " years\t"
+ yearsYearlyRate[1][i] + "%\t\t" + twoDigits.format(payment))
;
System.out.println("\nPaym
ent # \tMonthly Interest Paid \t\tRemaining Loan Balance");
interestBalanceList(mortga
ge, monthsMonthlyRt[1][i], monthsMonthlyRt[0][i], payment);
}
}
// I totally do not understand what this entire double tmp or param thing means. Please help !!!
public static double calPayment(double param1, double param2, double mortgage) {
double tmp = 1 + ( param1 ) ;
for ( int i = 1 ; i < param2 ; i++)
tmp = tmp * ( 1 + param1 ) ;
double monthlyPayment = mortgage * tmp * param1 / ( tmp - 1 ) ;
// double monthlyPayment = (param1 + param2 / (Math.pow((1 + param1), param2) - 1)) * mortgage;
return monthlyPayment;
}
public static void interestBalanceList(double
mortgage, double param1, double param2,
double payment)
{
for (int i = 1; i < (param2 + 1); i++) // Provide brief description please
{
System.out.println("Press 'ENTER' to view the loan amortization.");
try
{
System.in.read(); // what exactly is this providing my program ??? Do I even need it ???
} catch (Exception e)
{
}
// Calculate the Monthly Interest of the Loan Balance
double monthlyInterest = mortgage * param1;
// Calculate the Remaining Loan Balance
double loanRemaining = mortgage - (payment - monthlyInterest);
// Set the value of Mortgage Amount to the Value of the Remaining Loan Balance
mortgage = loanRemaining;
// Format the Monthly Interest Amount into U.S. Currency
NumberFormat n = NumberFormat.getCurrencyIn
stance(Loc
ale.US);
String str = n.format(monthlyInterest);
// Format the Remaining Loan Balance into U.S. Currency
NumberFormat num = NumberFormat.getCurrencyIn
stance(Loc
ale.US);
String string = num.format(loanRemaining);
// Display the Payment #, Monthly Interest Paid and Remaining Loan Balance
System.out.println("\n " + i + "\t\t\t" + str + "\t\t\t" + string); // Please explain the string
}
} // Also, I would like to make the program pause after showing 12 payments on the screen so
// how would I go about doing this ?????
}