1 changed files with 40 additions and 0 deletions
@ -0,0 +1,40 @@ |
|||||
|
public 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 String getOwnerName() { |
||||
|
return ownerName; |
||||
|
} |
||||
|
public void setOwnerName(String ownerName) { |
||||
|
this.ownerName=ownerName; |
||||
|
} |
||||
|
public String getAccountNumber() { |
||||
|
return accountNumber; |
||||
|
} |
||||
|
public double getBalance() { |
||||
|
return balance; |
||||
|
public void deposit(double amount) { |
||||
|
if (amount > 0) { |
||||
|
this.balance += amount; |
||||
|
System.out.println("存款成功!当前余额:" + this.balance + " 元"); |
||||
|
} else { |
||||
|
System.out.println("存款失败!存款金额必须大于0。"); |
||||
|
} |
||||
|
} |
||||
|
public void withdraw(double amount) { |
||||
|
if (amount <= 0) { |
||||
|
System.out.println("取款失败!取款金额必须大于0。"); |
||||
|
} else if (amount > this.balance) { |
||||
|
System.out.println("取款失败!余额不足,当前余额:" + this.balance + " 元"); |
||||
|
} else { |
||||
|
this.balance -= amount; |
||||
|
System.out.println("取款成功!当前余额:" + this.balance + " 元"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue