java 编写bankaccount类
时间: 2023-04-24 09:04:53 浏览: 181
BankAccount类是一个用Java编写的类,用于表示银行账户。它包含以下属性和方法:
属性:
- balance:表示账户余额
- accountNumber:表示账户号码
方法:
- deposit(amount):向账户中存入指定金额
- withdraw(amount):从账户中取出指定金额
- getBalance():获取账户余额
- getAccountNumber():获取账户号码
下面是一个示例代码:
public class BankAccount {
private double balance;
private String accountNumber;
public BankAccount(String accountNumber) {
this.accountNumber = accountNumber;
this.balance = ;
}
public void deposit(double amount) {
balance += amount;
}
public void withdraw(double amount) {
balance -= amount;
}
public double getBalance() {
return balance;
}
public String getAccountNumber() {
return accountNumber;
}
}
阅读全文