You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
|
|
class BankAccount {
|
|
private final String accountNumber;
|
|
private String ownerName;
|
|
private double balance;
|
|
|
|
public BankAccount(String accountNumber, String ownerName) {
|
|
this.accountNumber = accountNumber;
|
|
this.ownerName = ownerName;
|
|
this.balance = 0.0;
|
|
}
|
|
|
|
public void deposit(double amount) {
|
|
if (amount > 0) {
|
|
this.balance += amount;
|
|
System.out.println("[业务] 存入 $" + amount + " 成功。");
|
|
} else {
|
|
System.out.println("[业务] 存款失败:金额必须大于0。");
|
|
}
|
|
}
|
|
|
|
public void withdraw(double amount) {
|
|
if (amount > 0 && amount <= this.balance) {
|
|
this.balance -= amount;
|
|
System.out.println("[业务] 取出 $" + amount + " 成功。");
|
|
} else {
|
|
System.out.println("[业务] 取款失败:余额不足或金额无效。");
|
|
}
|
|
}
|
|
|
|
public double getBalance() {
|
|
return this.balance;
|
|
}
|
|
|
|
public String getOwnerName() {
|
|
return this.ownerName;
|
|
}
|
|
}
|