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; 
    }  
    }

}
public static void Main(String[] args) 

"main" is case-sensitive. You have "Main". It's looking for "main". Change "Main" to lower-case ("main"), recompile, and give it a try.

Edited 2 Months Ago by Dani: Formatting fixed after bug

Unfortunately, during the compile the changing of "Main" to "main" resulted in the same error.

The error message should include a line number... that's important

Anyway, line 82 of the second class refers to mortgage, which is a variable in the first class. You don't need that to call a method in the same class. You can just say calcC()

Edited 2 Months Ago by JamesCherrill

Dear JamesCherrill,
I changed line 82 of the second class from 'mortgage.calcC()' to 'CalcC'. Thank you so much for the help. I really appreciate it.
Before: mortgage.calcC();
After: CalcC();
Best Regards,
-Nol

Dear DaniWeb Community,
Should I include the CalcMthlyPymt (starts on line 47), CalcNmbrOfMthlyPymts (starts on line 59), and CalcMthlyIntRt (starts on line 71) methods in the while statement as CalcMthlyPymt(); CalcNmbrOfMthlyPymts(); and CalcMthlyIntRt(); ? Thank you again so much for the help.
Best Regards,
-Nol

Edited 2 Months Ago by Nol_1: The question contained a term that I wanted to change

This question has already been answered. Start a new discussion instead.