任何人都可以幫助我看到我錯過了這個?我正在嘗試獲取調用main方法的貸款類,並檢查我的異常處理是否正確。我對此非常陌生,準確的說,第六週可以使用所有可能的建設性幫助。提前致謝!Loan類型的Loan(double,int,double)方法未定義?
package loan;
import java.util.Scanner;
public class Loan {
public static void main(String[] args) {
try {
Loan(2.5, 0, 1000.00);
}
catch (IllegalArgumentException ex) {
ex.getMessage();
}
}
Scanner input = new Scanner(System.in);
double annualInterestRate;
int numberOfYears;
double loanAmount;
private java.util.Date loanDate;
public Loan() {
this(2.5, 0, 1000);
}
public Loan(double annualInterestRate, int numberOfYears, double loanAmount) {
this.annualInterestRate = annualInterestRate;
this.numberOfYears = numberOfYears;
this.loanAmount = loanAmount;
loanDate = new java.util.Date();
}
public double getAnnualInterestRate() {
if (annualInterestRate > 0)
return annualInterestRate;
else
throw new IllegalArgumentException("Interest rate cannot be zero or negative.");
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public int getNumberOfYears() {
if (numberOfYears > 0)
return numberOfYears;
else
throw new IllegalArgumentException("Number of years cannot be zero");
}
public void setNumberOfYears(int numberOfYears) {
this.numberOfYears = numberOfYears;
}
public double getLoanAmount() {
if (loanAmount > 0)
return loanAmount;
else
throw new IllegalArgumentException("Loan amount cannot be zero");
}
public void setLoanAmount(double loanAmount) {
this.loanAmount = loanAmount;
}
public double getMonthlyPayment() {
double monthlyInterestRate = annualInterestRate/1200;
double monthlyPayment = loanAmount * monthlyInterestRate/(1 - (Math.pow(1/(1 + monthlyInterestRate), numberOfYears *12)));
return monthlyPayment;
}
public double getTotalPayment() {
double totalPayment = getMonthlyPayment() * numberOfYears * 12;
return totalPayment;
}
public java.util.Date getLoanDate() {
return loanDate;
}
}
您能發佈實際錯誤嗎? – RonU