-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAccount.java
More file actions
47 lines (38 loc) · 1.21 KB
/
UserAccount.java
File metadata and controls
47 lines (38 loc) · 1.21 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
// UserAccount.java
import java.util.ArrayList;
public class UserAccount {
private String username;
private String pin;
private double balance;
private ArrayList<Transaction> transactions;
public UserAccount(String username, String pin, double balance) {
this.username = username;
this.pin = pin;
this.balance = balance;
this.transactions = new ArrayList<>();
}
public boolean authenticate(String pin) {
return this.pin.equals(pin);
}
public void deposit(double amount) {
balance += amount;
transactions.add(new Transaction("Deposit", amount));
}
public boolean withdraw(double amount) {
if (amount > balance) return false;
balance -= amount;
transactions.add(new Transaction("Withdraw", amount));
return true;
}
public void printTransactions() {
System.out.println("Transaction History:");
for (Transaction t : transactions) {
System.out.println(" - " + t);
}
}
public void changePIN(String newPIN) {
this.pin = newPIN;
}
public String getUsername() { return username; }
public double getBalance() { return balance; }
}