OOP - 贷款类错误

时间:2015-10-26 05:31:38

标签: java eclipse oop inheritance

你可以帮我解决这个问题..我很失落..

package Object;

public class Loan {

  private double annualinterestRate;
  private int numberofyears;
  private double loanamount;

  public Loan(){
  }

  public Loan(double annualinterestRate, int numberofyears, double loanamount)
  {
      this.annualinterestRate = annualinterestRate;
      this.numberofyears = numberofyears;
      this.loanamount = loanamount;
  }

  public double getAnnualinterestRate() {
      return annualinterestRate;
  }

  public void setAnnualinterestRate(double annualinterestRate) {
      this.annualinterestRate = annualinterestRate;
  }

  public int getNumberofyears() {
      return numberofyears;
  }

  public void setNumberofyears(int numberofyears) {
      this.numberofyears = numberofyears;
  }

  public double getLoanamount() {
      return loanamount;
  }

  public void setLoanamount(double loanamount) {
      this.loanamount = loanamount;
  }



  public double getMonthlyPayment()
  {
      double MonthIntRate = annualinterestRate/1200;
      double MonthlyPayment = (loanamount*MonthIntRate)/(1-(1/Math.pow(1+MonthIntRate,numberofyears*12)));
      return MonthlyPayment;
  }

  public double getTotalPayment()
  {
      return getMonthlyPayment()*numberofyears*12;
  }

  public String toString()
  {
      return "Annualint=" +annualinterestRate+ "Y=" +numberofyears+ "Amnt=" +loanamount+ "Monthly =" + MonthlyPayment();
  }

}

每月付款的字符串到字符串的最后一个方法有一些错误。它说 : ***此行有多个标记      - 方法MonthlyPayment()未定义      类型贷款      - MonthlyPayment无法解析为变量

这里的错误是什么

1 个答案:

答案 0 :(得分:0)

请更正编译错误,如下所示

错误代码

public String toString()
      {
          return "Annualint=" +annualinterestRate+ "Y=" +numberofyears+ "Amnt=" +loanamount+ "Monthly =" + MonthlyPayment();
      }

如上所述,MonthlyPayment()不是声明的方法,而是必须使用getMonthlyPayment()

更正代码

public String toString()
      {
          return "Annualint=" +annualinterestRate+ "Y=" +numberofyears+ "Amnt=" +loanamount+ "Monthly =" + getMonthlyPayment();
      }