From 8ba736b3786c668dc988b118d7734bc346d9727c Mon Sep 17 00:00:00 2001 From: Wanglixia <3035026499@qq.com> Date: Wed, 25 Mar 2026 23:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'src/w3'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/w3/BankAccount.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/w3/BankAccount.java diff --git a/src/w3/BankAccount.java b/src/w3/BankAccount.java new file mode 100644 index 0000000..18f561d --- /dev/null +++ b/src/w3/BankAccount.java @@ -0,0 +1,40 @@ +public class BankAccount { + private int accountNumber; + private String ownerName; + private double balance; + public BankAccount(int accountNumber,String ownerName,double balance) { + this.accountNumber = accountNumber; + this.balance = balance; + this.ownerName = ownerName; + } + public int getAccountNumber() { + return accountNumber; + } + public String getOwnerName() { + return ownerName; + } + public void setOwnerName(String ownerName) { + this.ownerName = ownerName; + } + public double getBalance() { + return balance; + } + //业务方法:存款 + public void deposit(double amount) { + if (amount > 0) { + balance += amount; + System.out.println("存款成功,当前余额: " + balance); + }else { + System.out.println("存款金额必须大于0"); + } + } + //业务方法:取款 + public void withdraw(double amount) { + if (amount > 0 && amount <= balance) { + balance -= amount ; + System.out.println("取款成功,当前余额: " + balance); + } else { + System.out.println("余额不足或金额无效"); + } + } +} \ No newline at end of file