LBryant777
IS-IT--Management
I started this out as one class, but I need to separate it out into different classes with constructors, getters and setters. I've gotten this far and now I'm lost. Plus now I get an error:
java.lang.Error: Unresolved compilation problem:
Syntax error on token "principal", ".", "[" expected
at school.MortgageCalculatorMain.main(MortgageCalculatorMain.java:30)
Exception in thread "main"
Here is the code for the different files:
MortgageCalculatorMain:
Code from MortgageCalculator:
Can someone help me? I really have a desire to learn and internalize this for the longhaul and not just for right now...thanks in advance!
java.lang.Error: Unresolved compilation problem:
Syntax error on token "principal", ".", "[" expected
at school.MortgageCalculatorMain.main(MortgageCalculatorMain.java:30)
Exception in thread "main"
Here is the code for the different files:
MortgageCalculatorMain:
Code:
import java.io.*;
import java.text.NumberFormat;
public class MortgageCalculatorMain {
public static void main(String[] args) throws IOException {//add throws Exception for keyboard input
final double principal = 200000;
final double interestRate[] = {5.35,5.5,5.75};
final double termInMonths[] = {84,180,360};
NumberFormat currency = NumberFormat.getCurrencyInstance(); //will format payment in currency form
// MortgageCalculator value = new MortgageCalculator();
// value.doCalculation();
for (int i = 1; i <= termInMonths.length; i++){ //prints out number of payments to be made
MortgageCalculator value = new MortgageCalculator();
MortgageCalculator.doCalculation(double principal, double interestRate[i], double termInMonths[i]);
}
}
}
Code from MortgageCalculator:
Code:
import java.io.*;
import java.text.NumberFormat;
public class MortgageCalculator {
//declare and initialize the variables
//formula that calculates monthly payment
public MortgageCalculator
{
public static void doCalculation(double principal, double InterestRate, double termInMonths)
double PeriodicRate, MonthlyIntPymt, MonthlyPrincipalPymt, Balance, LoanAmount, payment = 0;
PeriodicRate = interestRate/(100*12);
LoanAmount = principal+(principal*(interestRate/100)); //total amount to be repaid
payment = principal*(PeriodicRate / (1 - Math.pow(1 + PeriodicRate, -termInMonths))); //Mortgage Payment Amount
MonthlyIntPymt = principal*PeriodicRate; //calculates initial monthly interest payment
MonthlyPrincipalPymt = payment-MonthlyIntPymt; //calculates initial payment against principal loan
//print out results to screen
System.out.println("Principal: " + currency.format(principal));
System.out.println("Interest Rate: " + interestRate+"%");
System.out.println("Mortgage Term: " + Math.round(termInMonths/12) + " years");
System.out.println("Payment: " + currency.format(payment) + "\n\n\n");
int pymtNumber;
int counter = 0;
System.out.println("Payment #" + "\t" + "Interest" + "\t" + "Principal" + "\t" + "Balance" + "\n");
System.out.print(pymtNumber + "\t\t\t" + currency.format(MonthlyIntPymt)); //Interest payment
System.out.print("\t\t" + currency.format(MonthlyPrincipalPymt)); //Payment against principal
System.out.println("\t\t\t" + currency.format(principal-MonthlyPrincipalPymt)); //New Loan Balance
//next 3 formulas recalculate variables for next loop
principal = principal-MonthlyPrincipalPymt;
MonthlyIntPymt = principal*PeriodicRate;
MonthlyPrincipalPymt = payment-MonthlyIntPymt;
//for screen printing purposes
counter++;
if (counter==50)// pause on every 50 lines
{
System.out.println("\nPress the RETURN key to continue...\n");
byte[] buffer = new byte[50];
System.in.read(buffer);
counter = 0;
}
}
}
Can someone help me? I really have a desire to learn and internalize this for the longhaul and not just for right now...thanks in advance!