さて、私はこのクラスを持っています:
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 になり続けます。私は何を間違っていますか?