好的,所以我有这门课:
package com.sandrovictoriaarena.unittesting;
public class LoanCalculator {
private double pricipelValue; //PV
private double interestRate; //rate
private int loanLength; //n
private double result;
public LoanCalculator(double pricipelValue, double interestRate,
int loanLength) {
super();
this.pricipelValue = pricipelValue;
this.interestRate = interestRate / 100;
this.loanLength = loanLength;
}
public double getPricipelValue() {
return pricipelValue;
}
public void setPricipelValue(double pricipelValue) {
this.pricipelValue = pricipelValue;
}
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}
public int getLoanLength() {
return loanLength;
}
public void setLoanLength(int loanLength) {
this.loanLength = loanLength;
}
@Override
public String toString() {
return "LoanCalculator [pricipelValue=" +
pricipelValue + ", interestRate=" + interestRate +
", loanLength=" + loanLength + "]";
}
public double calculateMonthlyPayment() throws IllegalArgumentException{
result = (1 - (Math.pow((1 + interestRate), -1 * loanLength)));
result = interestRate / result;
result = result * pricipelValue;
return result;
}
}
我正在制作一个具有以下值的对象: new LoanCalculator (100.0,20.0,6);
我运行 calculateMonthlyPayment() 时的结果应该是 17.65,但我一直得到 30.07。我究竟做错了什么?