-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
143 lines (141 loc) · 4.78 KB
/
Main.java
File metadata and controls
143 lines (141 loc) · 4.78 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import java.util.*;
class ATM {
private double balance = 10000000.31;
private int pin = 1234;
private int attempts = 0;
private final int MAX_ATTEMPTS = 3;
private List<String> transactions = new ArrayList<>();
private Scanner sc = new Scanner(System.in);
public void checkPin() {
while (attempts < MAX_ATTEMPTS) {
System.out.print("Enter PIN: ");
int enteredPin = sc.nextInt();
if (enteredPin == pin) {
menu();
return;
} else {
attempts++;
System.out.println("Invalid PIN. Attempts left: " + (MAX_ATTEMPTS - attempts));
}
}
System.out.println("Account locked due to multiple incorrect attempts.");
}
public void menu() {
while (true) {
System.out.println("\n1. Check Balance");
System.out.println("2. Withdraw");
System.out.println("3. Deposit");
System.out.println("4. Transfer");
System.out.println("5. Transaction History");
System.out.println("6. Change PIN");
System.out.println("7. Fast Cash");
System.out.println("8. Exit");
System.out.print("Select option: ");
int choice = sc.nextInt();
switch (choice) {
case 1: checkBalance(); break;
case 2: withdraw(); break;
case 3: deposit(); break;
case 4: transfer(); break;
case 5: showTransactions(); break;
case 6: changePin(); break;
case 7: fastCash(); break;
case 8: return;
default: System.out.println("Invalid option.");
}
}
}
public void checkBalance() {
System.out.println("Current balance: " + balance);
}
public void withdraw() {
System.out.print("Enter amount: ");
double amount = sc.nextDouble();
if (amount <= 0) {
System.out.println("Invalid amount.");
return;
}
if (amount > balance) {
System.out.println("Insufficient balance.");
} else {
balance -= amount;
transactions.add("Withdraw: " + amount);
System.out.println("Withdrawal successful.");
System.out.println("Updated balance: " + balance);
}
}
public void deposit() {
System.out.print("Enter amount: ");
double amount = sc.nextDouble();
if (amount <= 0) {
System.out.println("Invalid amount.");
return;
}
balance += amount;
transactions.add("Deposit: " + amount);
System.out.println("Deposit successful.");
System.out.println("Updated balance: " + balance);
}
public void transfer() {
System.out.print("Enter account number: ");
long accountNumber = sc.nextLong();
System.out.print("Enter amount: ");
double amount = sc.nextDouble();
if (amount > balance) {
System.out.println("Insufficient balance.");
} else {
balance -= amount;
transactions.add("Transfer: " + amount + " to A/C " + accountNumber);
System.out.println("Transfer successful.");
}
}
public void showTransactions() {
if (transactions.isEmpty()) {
System.out.println("No transactions available.");
return;
}
System.out.println("Transaction History:");
for (String t : transactions) {
System.out.println(t);
}
}
public void changePin() {
System.out.print("Enter current PIN: ");
int currentPin = sc.nextInt();
if (currentPin == pin) {
System.out.print("Enter new PIN: ");
pin = sc.nextInt();
System.out.println("PIN updated successfully.");
} else {
System.out.println("Incorrect PIN.");
}
}
public void fastCash() {
System.out.println("1. 500");
System.out.println("2. 1000");
System.out.println("3. 5000");
System.out.print("Choose option: ");
int option = sc.nextInt();
int amount = 0;
if (option == 1) amount = 500;
else if (option == 2) amount = 1000;
else if (option == 3) amount = 5000;
else {
System.out.println("Invalid choice.");
return;
}
if (amount > balance) {
System.out.println("Insufficient balance.");
} else {
balance -= amount;
transactions.add("Fast Cash: " + amount);
System.out.println("Please collect your cash.");
}
}
}
public class Main {
public static void main(String[] args) {
ATM atm = new ATM();
atm.checkPin();
}
}