-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathATM.java
More file actions
57 lines (47 loc) · 1.6 KB
/
ATM.java
File metadata and controls
57 lines (47 loc) · 1.6 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
52
53
54
55
56
57
import java.util.ArrayList;
public class ATM {
private User currentUser;
// login process
public boolean login(String accNo, String pin) {
User user = BankDatabase.getUser(accNo);
if (user != null && user.getPin().equals(pin)) {
currentUser = user;
return true;
}
return false;
}
// OTP validation
public boolean verifyOTP(String generatedOTP, String enteredOTP) {
return generatedOTP.equals(enteredOTP);
}
public void deposit(double amount) {
currentUser.deposit(amount);
System.out.println(" ₹" + amount + " deposited successfully.");
}
public void withdraw(double amount) {
if (currentUser.withdraw(amount)) {
System.out.println(" ₹" + amount + " withdrawn successfully.");
} else {
System.out.println(" Insufficient balance.");
}
}
public void showBalance() {
System.out.println(" Current Balance: ₹" + currentUser.getBalance());
}
public void showMiniStatement() {
System.out.println(" Mini Statement:");
ArrayList<String> stmt = currentUser.getMiniStatement();
if (stmt.isEmpty()) {
System.out.println("Make some transactions dude");
}
else
for (String entry : stmt) {
System.out.println("• " + entry);
}
System.out.println("Available Balance " + currentUser.getBalance());
}
public void changePin(String newPin) {
currentUser.setPin(newPin);
System.out.println(" PIN changed successfully.");
}
}