Hello DaniWeb Community,
I'm a beginner Java programmer. The LoanTableTester contains the main method and the LoanTable is a class separate from the LoanTableTester class. May I please have help with a cannot find symbol - variable mortgage error? I wrote the methods for calculating the c, monthly payments, number of monthly payments and monthly interest rates in a separate class (LoanTable) that doesn't contain the main method. I researched how to do calculations within a while statement and I was confused on how to do it. Thank you to anyone who helps. It is greatly appreciated.
Best Regards,
-Nol
LoanTableTester.java
import apcslib.*;
import chn.util.*;
public class LoanTableTester
{
public static void Main(String[] args) //Main method
{
//instance variables
double loanAmt; //This is the loan amount in dollars
int loanLgth; //This is the length of the loan in years
double lowIntRt; //This is the lowIntRt expressed as a decimal
double highIntRt; //This is the highIntRt expressed as a decimal
ConsoleIO console = new ConsoleIO(); //ConsoleIO method
System.out.println("Enter the dollar amount of the loan ---> "); //User enters the dollar amount of the loan
loanAmt = console.readDouble(); //Takes user inout for loanAmt as a double
System.out.println("Enter the length of the loan in years ---> "); //User enters the length of the loan in years
loanLgth = console.readInt(); //Takes user input for loanLgth as an int
System.out.println("Enter the low interest rate of the loan as a decimal ---> "); //User enters the low interest rate of the loan as a decimal
lowIntRt = console.readDouble(); //Takes user input for lowIntRt as a double
System.out.println("Enter the high interest rate of the loan as a decimal ---> "); //User enters the high interest rate of the loan as a decimal
highIntRt = console.readDouble(); //Takes user input for highIntRt as a double
LoanTable mortgage = new LoanTable(loanAmt, loanLgth, lowIntRt, highIntRt); //loanAmt, loanLgth, lowIntRt and highIntRt are being passed as parameters
System.out.println("Mortgage problem"); //Prints out 'mortgage problem'
System.out.println("Principal: " + loanAmt); //Prints out loanAmt
System.out.println("Time: " + loanLgth + " years"); //Prints out the length of the loan in years
System.out.println("Low rate: " + lowIntRt); //Prints out the lowIntRt as a decimal
System.out.println("High rate: " + highIntRt); //Prints out the highIntRt as a decimal
}
}
LoanTable.java
import apcslib.*;
public class LoanTable
{
//instance variables
double loanAmt; //This is the variable 'p' for the loan amount in dollars
int loanLgth; //The length of the loan in years
double lowIntRt; //The low interest rate expressed as a decimal
double highIntRt; //The high interest rate expresed as a decimal
double mthlyIntRt; //The monthly interest rate ('k')
int nmbrOfMthlyPymts; //This is the number of monthly payments ('n')
double intRt; //The interest rate incremented by 0.25
double c; //The c value is to be calculated before determining the monthly payments
double annRt; //The annual rate
double mthlyPymt; //This is the variable 'a' for calculating the monthly payment
/**
* Constructor for objects of class LoanTable
*/
public LoanTable(double myloanAmt, int myloanLgth, double mylowIntRt, double myhighIntRt) //The identifiers in the paratheses of public LoanTable are 3 doubles and 1 int for the parameters
{
loanAmt = myloanAmt; //loanAmt is set equal to myloanAmt becuase myloanAmt is being passed into public LoanTable
loanLgth = myloanLgth; //loanLgth is set equal to myloanLgth becuase myloanLgth is being passed into public LoanTable
lowIntRt = mylowIntRt; //lowIntRt is set equal to mylowIntRt because mylowIntRt is being passed into public LoanTable
highIntRt = myhighIntRt; //highIntRt is set equal to myhighIntRt because myhighIntRt is being passed into public LoanTable
}
//Modifier for calculating the c value
/**
* Method CalcC
*
* @return The return value
*/
double CalcC()
{
c = Math.pow(1 + mthlyIntRt, nmbrOfMthlyPymts);
return c;
}
//Modifier for calculating the monthly payment
/**
* Method CalcMthlyPymt
*
* @return The return value
*/
double CalcMthlyPymt()
{
mthlyPymt = (loanAmt * mthlyIntRt * c) / (c - 1);
return mthlyPymt;
}
//Modifier for calculating the number of monthly payments
/**
* Method CalcNmbrOfMthlyPymts
*
* @return The return value
*/
double CalcNmbrOfMthlyPymts()
{
nmbrOfMthlyPymts = (loanLgth * 12);
return nmbrOfMthlyPymts;
}
//Modifier for calculating the monthly interest rate
/**
* Method CalcMthlyIntRt
*
* @return The return value
*/
double CalcMthlyIntRt()
{
mthlyIntRt = (annRt/12.0);
return mthlyIntRt;
}
public double MthlyLoop()
{
double intRt = lowIntRt;
while(intRt<highIntRt)
{ mortgage.calcC(); //cannot find symbol - variable mortgage
intRt += 0.25;
}
}
}