-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingSystem.java
More file actions
121 lines (112 loc) · 5.39 KB
/
BankingSystem.java
File metadata and controls
121 lines (112 loc) · 5.39 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
package PROJECT.Banking;
import java.sql.*;
import java.util.Scanner;
import static java.lang.Class.forName;
public class BankingSystem {
private static final String url = "jdbc:mysql://localhost:3306/BankingSystem";
private static final String username = "root";
private static final String password = "ad!tShh0828";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
try{
Class.forName("com.mysql.cj.jdbc.Driver");
}catch (ClassNotFoundException e){
System.out.println(e.getMessage());
}
try{
Connection connection = DriverManager.getConnection(url, username, password);
Scanner scanner = new Scanner(System.in);
user user = new user(connection, scanner);
Accounts accounts = new Accounts(connection, scanner);
AccountManager accountManager = new AccountManager(connection, scanner);
String email;
long account_number;
while(true){
System.out.println("*** WELCOME TO BANKING SYSTEM ***");
System.out.println();
System.out.println("1. Register");
System.out.println("2. Login");
System.out.println("3. Close an Account");
System.out.println("4. Exit");
System.out.println("Enter your choice: ");
int choice1 = scanner.nextInt();
switch (choice1){
case 1:
user.register();
break;
case 2:
email = user.login();
if(email!=null){
System.out.println();
System.out.println("User Logged In!");
if(!accounts.account_exist(email)){
System.out.println();
System.out.println("1. Open a new Bank Account");
System.out.println("3. Exit");
if(scanner.nextInt() == 1) {
account_number = accounts.open_account(email);
System.out.println("Account Created Successfully");
System.out.println("Your Account Number is: " + account_number);
} else{
break;
}
}
account_number = accounts.getAccount_number(email);
int choice2 = 0;
while (choice2 != 5) {
System.out.println();
System.out.println("1. Debit Money");
System.out.println("2. Credit Money");
System.out.println("3. Transfer Money");
System.out.println("4. Check Balance");
System.out.println("5. Log Out");
System.out.println("Enter your choice: ");
choice2 = scanner.nextInt();
switch (choice2) {
case 1:
accountManager.debit_money(account_number);
break;
case 2:
accountManager.credit_money(account_number);
break;
case 3:
accountManager.transfer_money(account_number);
break;
case 4:
accountManager.getBalance(account_number);
break;
case 5:
break;
default:
System.out.println("Enter Valid Choice!");
break;
}
}
}
else{
System.out.println("Incorrect Email or Password!");
break;
}
break;
case 3:
// System.out.println("Enter the account number: ");
// account_number = scanner.nextLong();
if(user.close_account()){
System.out.println("Account Closed Successfully!");
}else {
System.out.println("Account Closing Failed!");
}
break;
case 4:
System.out.println("THANK YOU FOR USING BANKING SYSTEM!!!");
System.out.println("Exiting System!");
return;
default:
System.out.println("Enter Valid Choice");
break;
}
}
}catch (SQLException e){
e.printStackTrace();
}
}
}