-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccount.java
37 lines (32 loc) · 1013 Bytes
/
BankAccount.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class BankAccount {
private String accountNumber;
private double balance;
public BankAccount(String accountNumber) {
this.accountNumber = accountNumber;
this.balance = 0.0; // Initial balance is 0
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposited: $" + amount);
} else {
System.out.println("Deposit amount must be positive.");
}
}
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.println("Withdrew: $" + amount);
} else if (amount > balance) {
System.out.println("Insufficient funds.");
} else {
System.out.println("Withdrawal amount must be positive.");
}
}
public double getBalance() {
return balance;
}
public String getAccountNumber() {
return accountNumber;
}
}