Js创建一个死期银行账户类
时间: 2023-08-28 22:10:24 浏览: 115
C 课程设计报告__银行账户管理系统.
以下是一个简单的 JavaScript 类,用于创建死期银行账户:
```javascript
class FixedDepositAccount {
constructor(accountNumber, accountHolderName, depositAmount, depositPeriod, interestRate) {
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.depositAmount = depositAmount;
this.depositPeriod = depositPeriod;
this.interestRate = interestRate;
}
calculateMaturityAmount() {
let maturityAmount = this.depositAmount * Math.pow(1 + (this.interestRate / 100), this.depositPeriod);
return maturityAmount.toFixed(2);
}
displayAccountDetails() {
console.log(`Account Number: ${this.accountNumber}`);
console.log(`Account Holder Name: ${this.accountHolderName}`);
console.log(`Deposit Amount: ${this.depositAmount}`);
console.log(`Deposit Period: ${this.depositPeriod} years`);
console.log(`Interest Rate: ${this.interestRate}%`);
console.log(`Maturity Amount: ${this.calculateMaturityAmount()}`);
}
}
```
使用该类创建一个死期银行账户对象的示例代码如下:
```javascript
let fdAccount = new FixedDepositAccount("FD001", "John Doe", 50000, 3, 8.5);
fdAccount.displayAccountDetails();
```
输出结果如下:
```
Account Number: FD001
Account Holder Name: John Doe
Deposit Amount: 50000
Deposit Period: 3 years
Interest Rate: 8.5%
Maturity Amount: 63718.96
```
这个类可以计算死期银行账户的到期金额,并显示账户的详细信息。你可以根据需要修改它来满足你的需求。
阅读全文