- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
谁能帮我看看我在哪里错过了这个?我试图将贷款类调用到主方法,并检查我的异常处理是否正确。我对此非常陌生,确切地说是第六周,并且可以使用所有可能的建设性帮助。提前致谢!
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;
}
}
最佳答案
尚不清楚您希望它在 main
中执行什么操作:
try {
Loan(2.5, 0, 1000.00);
}
我怀疑你的意思是它是一个构造函数调用:
try {
new Loan(2.5, 0, 1000.00);
}
您的帖子表明术语有些困惑,这可能导致了此问题:
I am trying to get the loan class called to the main method
你不调用一个类。您调用构造函数或方法。你的意思是:
I am trying to make the
main
method call the constructor for theLoan
class.
此时,您可能会更清楚地知道您需要new
。
关于java - Loan 类型的方法 Loan(double, int, double) 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8245216/
谁能帮我看看我在哪里错过了这个?我试图将贷款类调用到主方法,并检查我的异常处理是否正确。我对此非常陌生,确切地说是第六周,并且可以使用所有可能的建设性帮助。提前致谢! package loan; im
我的一台 Drupal 服务器最近遭到黑客攻击。虽然现在很干净,但我通过 /payday-loans 和 /leasehold-loans 获得了大量 Google 流量 和类似的。他们产生了足够的流
我正在尝试通过此处提供的官方 API 从 Lending Club 获取贷款 list :https://www.lendingclub.com/developers/listed-loans.act
管理员使用以下代码来保存 Loan 对象 import uuid from django.db import models from django.contrib.auth.models import
我需要在我的应用程序中计算 daysPastDue,这将由 DateTime.Now - Loan.DueDate 计算。 一个例子是:Loan.DueDate = 2/1/18 12:00:00Da
我是一名优秀的程序员,十分优秀!