-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
51 lines (44 loc) · 1.39 KB
/
Copy pathBankAccount.java
File metadata and controls
51 lines (44 loc) · 1.39 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.ArrayList;
import java.util.List;
public class BankAccount {
private String accountNumber;
private String accountHolder;
private double balance;
private List<String> transactions;
public BankAccount(String accountNumber, String accountHolder){
this.accountNumber = accountNumber;
this.accountHolder = accountHolder;
this.balance = 0.0;
this.transactions = new ArrayList<>();
}
public void deposit(double amount){
if (amount > 0){
balance += amount; //balance = balance + amount;
transactions.add("Deposited: " + amount);
System.out.println("Deposit successful");
}else{
System.out.println("Invalid amount!");
}
}
public void withdraw(double amount){
if(amount <= 0){
System.out.println("Invalid amount");
}
else if (amount <= balance){
balance -= amount; //balance = balance - amount;
transactions.add("Withdrew :" + amount);
System.out.println("Withdrawal successful");
} else{
System.out.println("Insufficient funds");
}
}
public double getBalance(){
return balance;
}
public void showTransactions(){
System.out.println("Transaction History:");
for (String t : transactions){
System.out.println(t);
}
}
}