-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankApp.java
More file actions
95 lines (86 loc) · 3.87 KB
/
BankApp.java
File metadata and controls
95 lines (86 loc) · 3.87 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
import java.util.*;
public class BankApp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Bank bank = new Bank();
while (true) {
System.out.println("\n--- BANKING SYSTEM ---");
System.out.println("1. Create Account\n2. Deposit\n3. Withdraw\n4. Transfer\n5. Mini Statement\n6. Exit");
System.out.print("Choose option: ");
int choice = sc.nextInt();
sc.nextLine(); // consume newline
switch (choice) {
case 1:
System.out.print("Enter Account Number: ");
String accNo = sc.nextLine();
System.out.print("Enter Holder Name: ");
String name = sc.nextLine();
bank.createAccount(accNo, name);
System.out.println("Account Created.");
break;
case 2:
System.out.print("Enter Account Number: ");
accNo = sc.nextLine();
Account acc = bank.getAccount(accNo);
if (acc != null) {
System.out.print("Enter Amount: ");
double amt = sc.nextDouble();
acc.deposit(amt);
bank.recordTransaction(accNo, "deposit", amt);
System.out.println("Amount Deposited.");
} else {
System.out.println("Account not found.");
}
break;
case 3:
System.out.print("Enter Account Number: ");
accNo = sc.nextLine();
acc = bank.getAccount(accNo);
if (acc != null) {
System.out.print("Enter Amount: ");
double amt = sc.nextDouble();
if (acc.withdraw(amt)) {
bank.recordTransaction(accNo, "withdraw", amt);
System.out.println("Amount Withdrawn.");
} else {
System.out.println("Insufficient balance.");
}
} else {
System.out.println("Account not found.");
}
break;
case 4:
System.out.print("Enter From Account: ");
String from = sc.nextLine();
System.out.print("Enter To Account: ");
String to = sc.nextLine();
System.out.print("Enter Amount: ");
double amt = sc.nextDouble();
Account fromAcc = bank.getAccount(from);
Account toAcc = bank.getAccount(to);
if (fromAcc != null && toAcc != null) {
if (fromAcc.transfer(toAcc, amt)) {
bank.recordTransaction(from, "transfer", amt);
bank.recordTransaction(to, "receive", amt);
System.out.println("Transfer Successful.");
} else {
System.out.println("Transfer Failed. Insufficient funds.");
}
} else {
System.out.println("Account(s) not found.");
}
break;
case 5:
System.out.print("Enter Account Number: ");
accNo = sc.nextLine();
System.out.println("Mini Statement:");
bank.showMiniStatement(accNo);
break;
case 6:
System.out.println("Thank you for using our banking app!");
sc.close();
System.exit(0);
}
}
}
}