(IllegalArgumentException异常)修改程序清单10-2中的Loan类,如果贷款总额、利率、年数小于或等于零,则抛出IllegalArgumentException异常
2021/5/16 20:25:42
本文主要是介绍(IllegalArgumentException异常)修改程序清单10-2中的Loan类,如果贷款总额、利率、年数小于或等于零,则抛出IllegalArgumentException异常,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public class Loan { private double annualInterestRate; private int numberOfYears; private double loanAmount; private java.util.Date loanDate; public Loan() { this(2.5, 1, 1000); } public Loan(double annualInterestRate, int numberOfYears, double loanAmount) { this.annualInterestRate = annualInterestRate; this.numberOfYears = numberOfYears; this.loanAmount = loanAmount; loanDate = new java.util.Date(); judge(); } public void judge() throws IllegalArgumentException{ if(this.loanAmount<=0) { throw new IllegalArgumentException("贷款总额小于等于0!"); } if(this.annualInterestRate<=0) { throw new IllegalArgumentException("利率小于等于0!"); } if(this.numberOfYears<=0) { throw new IllegalArgumentException("贷款年数小于等于0!"); } } public double getAnnualInterestRate() { return annualInterestRate; } public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; judge(); } public int getNumberOfYears() { return numberOfYears; } public void setNumberOfYears(int numberOfYears) { this.numberOfYears = numberOfYears; judge(); } public double getLoanAmount() { return loanAmount; } public void setLoanAmount(double loanAmount) { this.loanAmount = loanAmount; judge(); } public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / Math.pow(1+monthlyInterestRate, numberOfYears * 12))); return monthlyPayment; } public double getTotalPayment() { double totalPayment = getMonthlyPayment() * numberOfYears * 12; return totalPayment; } public java.util.Date getLoanDate(){ return loanDate; } }
这篇关于(IllegalArgumentException异常)修改程序清单10-2中的Loan类,如果贷款总额、利率、年数小于或等于零,则抛出IllegalArgumentException异常的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-25安卓NDK 是什么?-icode9专业技术文章分享
- 2024-12-25caddy 可以定义日志到 文件吗?-icode9专业技术文章分享
- 2024-12-25wordfence如何设置密码规则?-icode9专业技术文章分享
- 2024-12-25有哪些方法可以实现 DLL 文件路径的管理?-icode9专业技术文章分享
- 2024-12-25错误信息 "At least one element in the source array could not be cast down to the destination array-icode9专业技术文章分享
- 2024-12-25'flutter' 不是内部或外部命令,也不是可运行的程序 或批处理文件。错误信息提示什么意思?-icode9专业技术文章分享
- 2024-12-25flutter项目 as提示Cannot resolve symbol 'embedding'提示什么意思?-icode9专业技术文章分享
- 2024-12-24怎么切换 Git 项目的远程仓库地址?-icode9专业技术文章分享
- 2024-12-24怎么更改 Git 远程仓库的名称?-icode9专业技术文章分享
- 2024-12-24更改 Git 本地分支关联的远程分支是什么命令?-icode9专业技术文章分享