I have been correcting the arrays, and still need help with how I am putting this together. I have called out the interest rates, years, and need to printout all three mortgage payments for only one month. Any suggestions?
import java.text.DecimalFormat;
//
public class MortgagePayment
{
public void calc(double interest, double principle, int monthlypayments)
{
//Declare and construct the 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){}
}
}
}
}
first of, your variable declaration
if you want to declare an array to type say int with name say myintegerarray it has to take the form
int[] myintegerarray = {….}
notice you have to tell java what type of variable array myintegerarray is first, when you use myintegerarray[] java tries to create an array of type myintegerarray which unless defined in a separate class will produce a compilation error.
My suggestion, fix your variable declarations first, re – run and if there is anything else, let us know and I will be more than happy to help,
Regards,
David
ps – what IDE are you using (I recommend Eclipse for CMD development – Netbeans for GUI development)
first of, your variable declaration
if you want to declare an array to type say int with name say myintegerarray it has to take the form
int[] myintegerarray = {….}
notice you have to tell java what type of variable array myintegerarray is first, when you use myintegerarray[] java tries to create an array of type myintegerarray which unless defined in a separate class will produce a compilation error.
My suggestion, fix your variable declarations first, re – run and if there is anything else, let us know and I will be more than happy to help,
Regards,
David
ps – what IDE are you using (I recommend Eclipse for CMD development – Netbeans for GUI development)
References :