设计一个bankaccount类java
时间: 2023-04-27 19:00:52 浏览: 119
JAVA实现银行账户类
5星 · 资源好评率100%
```java
public class BankAccount {
private double balance;
private String accountNumber;
public BankAccount(double balance, String accountNumber) {
this.balance = balance;
this.accountNumber = accountNumber;
}
public double getBalance() {
return balance;
}
public String getAccountNumber() {
return accountNumber;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
if (amount > balance) {
System.out.println("Insufficient funds.");
} else {
balance -= amount;
}
}
}
```
上面是一个简单的银行账户类,可以存钱,取钱,查询余额和账号。
如果需要更多功能,可以继续添加方法。
阅读全文