Java语言声明账户类Account,成员变量包括账号,储户姓名,开户时间,身份证号码,存款余额等账户信息,成员方法包括开户,存款,取款,查询,销户等操作
时间: 2024-06-15 08:04:11 浏览: 275
java银行账户及相关操作
Java语言声明账户类Account,可以包含以下成员变量和成员方法:
```java
public class Account {
private String accountNumber; // 账号
private String accountHolderName; // 储户姓名
private Date openingDate; // 开户时间
private String idNumber; // 身份证号码
private double balance; // 存款余额
// 构造方法
public Account(String accountNumber, String accountHolderName, Date openingDate, String idNumber, double balance) {
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.openingDate = openingDate;
this.idNumber = idNumber;
this.balance = balance;
}
// 开户
public void openAccount(String accountNumber, String accountHolderName, Date openingDate, String idNumber, double balance) {
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.openingDate = openingDate;
this.idNumber = idNumber;
this.balance = balance;
}
// 存款
public void deposit(double amount) {
balance += amount;
}
// 取款
public void withdraw(double amount) {
if (balance >= amount) {
balance -= amount;
} else {
System.out.println("余额不足");
}
}
// 查询余额
public double getBalance() {
return balance;
}
// 销户
public void closeAccount() {
accountNumber = null;
accountHolderName = null;
openingDate = null;
idNumber = null;
balance = 0.0;
}
}
```
阅读全文