-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
208 lines (205 loc) · 8.42 KB
/
Bank.java
File metadata and controls
208 lines (205 loc) · 8.42 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
import java.util.*;
class Data
{
static String name[] = new String[3];
static String accountnum[] = new String[3];
static String id[] = new String[3];
static String password[] = new String[3];
static Scanner sc = new Scanner(System.in);
static Scanner in = new Scanner(System.in);
static int[] amount = new int[3];
static int[] FD = new int[3];
static String lid,lpassword,pname,paccountno;
static int pamount;
static boolean hello = false;
public void create()
{
for(int i=0;i<3;i++)
{
System.out.println("Enter your Name : ");
name[i] = sc.nextLine();
System.out.println("Enter your User Name : ");
id[i] = sc.nextLine();
System.out.println("Enter your Password : ");
password[i] = sc.nextLine();
System.out.println("Enter your Amount : ");
amount[i] = in.nextInt();
accountnum[i]="00"+(i+1);
System.out.println("Your acoount has been created successfully.");
System.out.println("Your Account Number is "+accountnum[i]);
}
}
public void login()
{
System.out.println("Enter User Name : ");
lid = sc.nextLine();
System.out.println("Enter Your Password : ");
lpassword = sc.nextLine();
for(int i=0;i<3;i++)
{
if(lid.equals(id[i])&&lpassword.equals(password[i]))
System.out.println("Login Successful.");
}
for(int i=0;i<3;i++)
{
if(!lid.equals(id[i])&&!lpassword.equals(password[i]))
System.out.println("User Name or Password not match.");
break;
}
}
public void Display()
{
for(int i=0;i<3;i++)
{
if(lid==null&&lpassword==null)
{
System.out.println("Please Login First.");
break;
}
if(lid.equals(id[i])&&lpassword.equals(password[i]))
{
System.out.println("Account Holder Name = "+name[i]);
System.out.println("Account Number = "+accountnum[i]);
System.out.println("User Name = "+id[i]);
System.out.println("Amount = "+amount[i]);
System.out.println("FD Amount = "+FD[i]);
}
}
}
public void Transfer()
{
System.out.println("Enter Paypee Name : ");
pname = sc.nextLine();
System.out.println("Enter Paypee Account No : ");
paccountno = sc.nextLine();
System.out.println("Enter Amount to Transfer : ");
pamount = in.nextInt();
for(int i=0;i<3;i++)
{
if(pname.equals(name[i])&&paccountno.equals(accountnum[i]))
{
for(int j=0;j<3;j++)
{
if(lid.equals(id[j])&&lpassword.equals(password[j]))
{
hello=true;
if(pamount<=amount[j])
{
amount[j] = amount[j]-pamount;
amount[i]=amount[i]+pamount;
System.out.println("Your Transaction Successfully");
System.out.println("Transaction Detail : ");
System.out.println(" Paypee Name : "+pname);
System.out.println(" Paypee Account No : "+paccountno);
System.out.println(" Transferd Amount : "+pamount);
}
else
System.out.println("Transaction fail because your balance is low.");
break;
}
}
}
}
if(!hello)
System.out.println("Paypee account does not exits.");
}
public void FD()
{
for(int i=0;i<3;i++)
{
if(lid==null&&lpassword==null)
{
System.out.println("Please Login First.");
break;
}
if(lid.equals(id[i])&&lpassword.equals(password[i]))
{
System.out.println("Enter amount for FD : ");
FD[i] = in.nextInt();
if(FD[i]<=amount[i])
{
amount[i] = amount[i]-FD[i];
System.out.println("FD Done Successfully.");
System.out.println("FD price is "+FD[i]);
}
else
System.out.println("Fail!!!!\nFD price is greater then your account balance.");
}
}
}
}
public class Bank extends Data
{
static Data d = new Data();
static Scanner sc = new Scanner(System.in);
static Scanner in = new Scanner(System.in);
static int choice;
static boolean loop = true;
public static void main(String[] args)
{
System.out.println("Welcome to Bank\n");
do
{
System.out.println("Select 1 for Open Account");
System.out.println("Select 2 for Login");
System.out.println("Select 3 for Account Detail");
System.out.println("Select 4 for Fund Transfer");
System.out.println("Select 5 for Open FD");
System.out.println("Select 6 for Logout");
System.out.println("Select 7 for Exit");
try{
choice = Integer.parseInt(in.next());
}catch(NumberFormatException e){
System.out.println("Error 121: Enter valid input.");
continue;
}
switch(choice)
{
case 1:
d.create();
break;
case 2:
d.login();
break;
case 3:
d.Display();
break;
case 4:
if(lid==null&&lpassword==null)
{
System.out.println("Please Login First.");
break;
}
d.Transfer();
break;
case 5:
d.FD();
break;
case 6:
if(lid==null&&lpassword==null)
{
System.out.println("Please Login First.");
break;
}
lid=null;
lpassword=null;
System.out.println("Logout successfully.");
System.out.println("Do you want to Exit?(y/n)");
String c = sc.nextLine();
if(c.equals("n")||c.equals("n"))
break;
else
{
loop=false;
System.exit(0);
}
case 7:
System.exit(0);
break;
default:
System.out.println("Please Select Number Between 1 to 7.");
break;
}
}while(loop);
}
}