-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM.java
More file actions
290 lines (259 loc) · 10.4 KB
/
ATM.java
File metadata and controls
290 lines (259 loc) · 10.4 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import java.util.Scanner;
class ATM {
private static int balance = 60000;
public static void main(String[] args) {
Pin pin = new Pin();
CashWithdrawal cashWithdrawal = new CashWithdrawal();
MoneyTransfer moneyTransfer = new MoneyTransfer();
Deposit deposit = new Deposit();
BalanceEnquiry balanceEnquiry = new BalanceEnquiry();
BalanceEnquiryReceipt balanceEnquiryReceipt = new BalanceEnquiryReceipt();
System.out.println("\n\n*******Insert your card*******");
System.out.println("Wait, your card information is getting processed...");
pin.enterPin();
System.out.println("\n1. Cash withdrawal");
System.out.println("2. Money transfer");
System.out.println("3. Deposit");
System.out.println("4. Balance Enquiry");
System.out.println("5. Cancel\n");
System.out.print("Enter your choice: ");
int choice;
Scanner scanner = new Scanner(System.in);
choice = scanner.nextInt();
switch (choice) {
case 1:
cashWithdrawal.cashWithdrawal();
if (cashWithdrawal.getCurrentWithdrawal() || cashWithdrawal.getSavingsWithdrawal() || cashWithdrawal.getCreditWithdrawal()) {
System.out.print("Do you want a receipt? Choose Y for Yes or N for No: ");
char receiptChoice = scanner.next().charAt(0);
if (receiptChoice == 'Y' || receiptChoice == 'y') {
WithdrawalReceipt withdrawalReceipt = new WithdrawalReceipt();
withdrawalReceipt.withdrawalReceipt(cashWithdrawal);
}
}
break;
case 2:
moneyTransfer.moneyTransfer();
if (moneyTransfer.getTransferSuccess()) {
System.out.print("Do you want a receipt? Choose Y for Yes or N for No: ");
char receiptChoice = scanner.next().charAt(0);
if (receiptChoice == 'Y' || receiptChoice == 'y') {
TransferReceipt transferReceipt = new TransferReceipt();
transferReceipt.transferReceipt(moneyTransfer);
}
}
break;
case 3:
deposit.deposit();
if (deposit.getDepositSuccess()) {
System.out.print("Do you want a receipt? Choose Y for Yes or N for No: ");
char receiptChoice = scanner.next().charAt(0);
if (receiptChoice == 'Y' || receiptChoice == 'y') {
DepositReceipt depositReceipt = new DepositReceipt();
depositReceipt.depositReceipt(deposit);
}
}
break;
case 4:
balanceEnquiry.balanceEnquiry();
System.out.print("Do you want a receipt? Choose Y for Yes or N for No: ");
char receiptChoice = scanner.next().charAt(0);
if (receiptChoice == 'Y' || receiptChoice == 'y') {
balanceEnquiryReceipt.balanceReceipt(cashWithdrawal, moneyTransfer, deposit, pin);
}
break;
case 5:
break;
default:
System.out.println("Invalid Choice");
break;
}
}
public static int getBalance() {
return balance;
}
public static void setBalance(int newBalance) {
balance = newBalance;
}
}
class Pin {
public void enterPin() {
int i;
for (i = 1; i < 4; i++) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your PIN: ");
String pinNum = scanner.next();
if (pinNum.equals("3400")) {
break;
} else {
System.out.println("Access Denied!!! You have " + (3 - i) + " more chances left");
}
}
if (i == 4) {
System.out.println("Sorry! You have exhausted your chances of entering the PIN. You cannot access the ATM anymore.");
System.exit(0);
}
}
}
class CashWithdrawal {
private int amount;
private boolean currentWithdrawal = false;
private boolean savingsWithdrawal = false;
private boolean creditWithdrawal = false;
public void cashWithdrawal() {
System.out.println("\nChoose one of the following:-");
System.out.println("1. Current");
System.out.println("2. Savings");
System.out.println("3. Credit");
System.out.println("4. Cancel");
System.out.print("Enter your choice: ");
Scanner scanner = new Scanner(System.in);
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter the amount to be withdrawn: ");
amount = scanner.nextInt();
int limit;
if (ATM.getBalance() > amount) {
limit = 50000;
if (amount < limit) {
System.out.println("Transaction in progress...");
System.out.println("Amount withdrawn\n");
ATM.setBalance(ATM.getBalance() - amount);
currentWithdrawal = true;
} else {
System.out.println("Limit exceeded. Enter an amount within 50000\n");
}
} else {
System.out.println("Insufficient balance\n");
}
break;
case 2:
System.out.print("Enter the amount to be withdrawn: ");
amount = scanner.nextInt();
if (ATM.getBalance() > amount) {
limit = 24000;
if (amount < limit) {
System.out.println("Transaction in progress...");
System.out.println("Amount withdrawn\n");
ATM.setBalance(ATM.getBalance() - amount);
savingsWithdrawal = true;
} else {
System.out.println("Limit exceeded. Enter an amount within 24000!");
}
} else {
System.out.println("Insufficient balance!\n");
}
break;
case 3:
System.out.print("Enter the amount to be withdrawn: ");
amount = scanner.nextInt();
System.out.println("Cash advance fee of 2.5% is levied on the cash withdrawn");
creditWithdrawal = true;
break;
case 4:
break;
default:
System.out.println("Press again");
break;
}
}
public boolean getCurrentWithdrawal() {
return currentWithdrawal;
}
public boolean getSavingsWithdrawal() {
return savingsWithdrawal;
}
public boolean getCreditWithdrawal() {
return creditWithdrawal;
}
public int getAmount() {
return amount;
}
}
class WithdrawalReceipt {
public void withdrawalReceipt(CashWithdrawal cashWithdrawal) {
System.out.println("Cash withdrawn of Rs. " + cashWithdrawal.getAmount() + " from the account");
}
}
class MoneyTransfer {
private int amount;
private boolean transferSuccess = false;
private long accountNum;
public void moneyTransfer() {
System.out.print("Enter the amount: ");
Scanner scanner = new Scanner(System.in);
amount = scanner.nextInt();
System.out.println("Validating balance from the bank...");
if (ATM.getBalance() > amount) {
System.out.print("Enter the account number of the receiver: ");
accountNum = scanner.nextLong();
System.out.println("Waiting for the money to get transferred...\n");
System.out.println("Money transfer successful\n");
transferSuccess = true;
ATM.setBalance(ATM.getBalance() - amount);
} else {
System.out.println("Insufficient balance. Transfer not possible");
}
}
public int getAmount() {
return amount;
}
public boolean getTransferSuccess() {
return transferSuccess;
}
public long getAccountNum() {
return accountNum;
}
}
class TransferReceipt {
public void transferReceipt(MoneyTransfer moneyTransfer) {
System.out.println("Cash transferred of Rs." + moneyTransfer.getAmount() + " to account number " + moneyTransfer.getAccountNum());
}
}
class Deposit {
private int amount;
private boolean depositSuccess = false;
public void deposit() {
System.out.print("Enter the amount: ");
Scanner scanner = new Scanner(System.in);
amount = scanner.nextInt();
int limit = 100000;
if (amount < limit) {
System.out.println("Amount deposited successfully");
depositSuccess = true;
ATM.setBalance(ATM.getBalance() + amount);
} else {
System.out.println("Limit exceeded. Enter an amount within 100000!");
}
}
public int getAmount() {
return amount;
}
public boolean getDepositSuccess() {
return depositSuccess;
}
}
class DepositReceipt {
public void depositReceipt(Deposit deposit) {
System.out.println("\nCash of Rs." + deposit.getAmount() + " deposited into the account");
}
}
class BalanceEnquiry {
public void balanceEnquiry() {
System.out.println("Balance of Rs. " + ATM.getBalance() + " remaining in the account");
}
}
class BalanceEnquiryReceipt {
public void balanceReceipt(CashWithdrawal cashWithdrawal, MoneyTransfer moneyTransfer, Deposit deposit, Pin pin) {
if (cashWithdrawal.getCurrentWithdrawal()) {
System.out.println("\nBalance of Rs." + ATM.getBalance() + " remaining in current account");
} else if (cashWithdrawal.getSavingsWithdrawal()) {
System.out.println("\nBalance of Rs." + ATM.getBalance() + " remaining in savings account");
} else if (moneyTransfer.getTransferSuccess()) {
System.out.println("\nBalance of Rs." + ATM.getBalance() + " remaining in the account");
} else if (deposit.getDepositSuccess()) {
System.out.println("\nBalance of Rs." + ATM.getBalance() + " remaining in the account");
}
}
}