Hi everyone! I'm creating a class for a mortgage payment. I pretty much have most of the code finished but when I compile the code I receive multiple errors saying "Cannot find symbol". This error occurs about 9 times and I am also having some problems with the compareTo method. If anyone can help me that would be greatly appreciated.

Thanks in advance.

Here's the code:

import java.io.*;
import java.util.*;
import java.lang.*;

public class Loan implements Comparable<Loan>
  private double borrowed;
  private double interestRate;
  private int years;

  public Loan()
    borrowed    = 0;
    interestRate   = 0;
    years = 0;

  public Loan(double tborrowed, double interestR, int tyears)
      borrowed   = tborrowed;
      interest = interestR;
      years = tyears;

  public void setBorrowed(double tborrowed)
  { borrowed = tborrowed; }

  public double getBorrowed()
  { return borrowed; }

  public void setInterest(double interestR)
  { interest = interestR; }

  public double getInterest()
  { return interest; }

  public void setYears(int tyears)
  { years = tyears; }

  public int getYears()
  { return years; }

  public double monthlyPayment()
      double N = years * -12;
	  double R = interest * 0.01;
	  R = R/12;
      double monthlypayment = (amount * R) / (1 - (Math.pow(1 + R, N)));
      return monthlypayment;

  public double totalPayment()
     double totalPayment = 0;
     int months = years * 12;

     for (int i = 0; i <= months; i++)
		 totalPayment += Loan.monthlyPayment;

	 return totalPayment;

  public double totalInterest()
    double totalInterest = Loan.totalPayment - borrowed;

  	return totalInterest;

  public String toString()
  { return borrowed + "  " + Loan.monthlyPayment;}

  public int compareTo(Loan otherLoan)
      return borrowed.compareTo(otherLoan.borrowed);


Recommended Answers

All 3 Replies

interest is not declared. Use interestRate .

Have a look at line #22

It must be,

interestRate = interestR;

"Symbol not found" means you're using a name that the compiler doesn't know. It could be a variable that's not visible in this part of the code (ie, you declared something in one method, but you're trying to use it in another) or you declared a variable and you're using the wrong name for it, or you just never declared it - these are the most typical cases.

In this case, adatapost is right - you're using a variable called interest which hasn't been declared.

For your compareTo, you're trying to call a method of "borrowed" which is a double. Primitives don't have methods in java. You need to figure out a way to fulfill the comparable contract, either by using primitive comparisons or I suppose by converting to the Double wrapper class and using the compareTo method of that class. I'd go with primitive comparisons.

Thanks adatapost I have it working how I want it to work now. I feel awful thick now after looking at the code and using interest when I meant interestRate.

Jon, thanks I'll just go with primitives for the compareTo method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.