-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
342 lines (311 loc) · 10.7 KB
/
Copy pathBank.java
File metadata and controls
342 lines (311 loc) · 10.7 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/**** Class Account ***/
import java.util.Scanner;
class Account
{
private int accno;
private double balance;
protected double minbalance;
public Account(int ac, double bal, double minbal)
{
accno= ac;
balance = bal;
minbalance = minbal;
}
protected int getAccno()
{
return accno;
}
protected double getBalance()
{
return balance;
}
protected void setBalance(double bal)
{
balance = bal;
}
protected double getMinBalance()
{
return minbalance;
}
protected void setMinBalance(int bal)
{
minbalance = bal;
}
}
class SavingAccount extends Account
{
private double interest;
static private double rate;
static int temp = 100;
public SavingAccount(double bal, double minbal)
{
//int accno;
super(generateAccountNumber(), bal,minbal);
interest =0;
rate = 4.5;
}
private static int generateAccountNumber()
{
return temp++;
}
static public double getRate()
{
return rate;
}
public void deposit(int amt)
{
setBalance(super.getBalance()+amt);
}
public void withdraw(int amt)
{
if(getBalance()-amt >= minbalance)
setBalance(getBalance()-amt);
else
{
System.out.println("Your Balance is less: "+getBalance());
}
}
public void showBalance()
{
System.out.println("Your Balance is: " + getBalance());
}
public int getAccno()
{
return super.getAccno();
}
public static void modifyRate(double irate)
{
rate = irate;
}
public void calInterest()
{
interest = getBalance()*this.getRate()/100;
setBalance(getBalance()+interest);
}
public void showDetails()
{
System.out.println("Account Type: Saving Account");
System.out.println("Account No:"+this.getAccno());
System.out.println("Balance: "+super.getBalance());
System.out.println("Min Balance: "+super.getMinBalance());
}
}
class CurrentAccount extends Account
{
private double overdraft;
private double penaltyrate;
private double creditlimit;
private double penalty;
static int temp = 1100;
public CurrentAccount(double bal, double minbal,double credit)
{
//int accno;
super(generateAccountNumber(), bal,minbal);
creditlimit = credit;
overdraft =0;
penaltyrate = 3.5;
penalty=0;
}
private static int generateAccountNumber()
{
return temp++;
}
public void deposit(int amt)
{
setBalance(super.getBalance()+amt);
if(getBalance() >=getMinBalance())
{
penalty = overdraft*penaltyrate;
setBalance(super.getBalance()-penalty);
overdraft =0;
}
else
overdraft = overdraft-amt+penalty;
}
public void withdraw(int amt)
{
if(getBalance()-getMinBalance()>=amt)
{
setBalance(getBalance()-amt);
penalty = 0;
}
else
if(amt<=creditlimit)
{
overdraft = getBalance()+getMinBalance()-amt;
setBalance(getBalance()-amt);
}
else
{
System.out.println("Your withdrawl request exceeded credit limit: "+getBalance());
System.out.println("Your credit limit: "+creditlimit);
}
}
public void showBalance()
{
System.out.println("Your Balance is: " + getBalance());
}
public int getAccno()
{
return super.getAccno();
}
public void showDetails()
{
System.out.println("Account Type: Current Account");
System.out.println("Account No: "+this.getAccno());
System.out.println("Balance: "+super.getBalance());
System.out.println("Min Balance: "+super.getMinBalance());
System.out.println("Credit Limit: "+this.creditlimit);
System.out.println("Overdraft: "+this.overdraft);
System.out.println("Penaltyrate: "+this.penaltyrate);
System.out.println("penalty : "+this.penalty);
}
}
/****** Class Bank ******/
public class Bank
{
public static int search(SavingAccount save[], int acno, int size)
{
int i;
for(i=0;i<size;i++)
if(save[i].getAccno() == acno)
return i;
return -1;
}
public static int search(CurrentAccount cur[], int acno, int size)
{
int i;
for(i=0;i<size;i++)
if(cur[i].getAccno() == acno)
return i;
return -1;
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
SavingAccount save[] = new SavingAccount[10];
CurrentAccount cur[] = new CurrentAccount[5];
int i=0, j=0, pos,amt,accno;
char ch;
/* Perform Bank operations */
do
{
System.out.println("\nLNMIIT Banking System\n");
System.out.println("1. open new saving account");
System.out.println("2. open new current account");
System.out.println("3. deposit in saving account");
System.out.println("4. deposit in current account");
System.out.println("5. withdraw from saving account");
System.out.println("6. withdraw from current account");
System.out.println("7. Show Balance Saving Account");
System.out.println("8. Show Balance Current Account");
System.out.println("9. Show Details Saving Account");
System.out.println("10. Show Details Current Account");
System.out.println("11. Quit");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
//System.out.println("Enter your details");
save[i] = new SavingAccount(5000,5000);
save[i].showDetails();
//save[i].getData(scan);
i++;
break;
case 2 :
System.out.println("Enter your details");
cur[j] = new CurrentAccount(10000,10000,50000);
cur[j].showDetails();
j++;
break;
case 3 :
System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(save,accno,i);
if(pos>=0)
{
System.out.println("Enter the amount to be deposited");
amt = scan.nextInt() ;
save[pos].deposit(amt);
}
else
System.out.println("Account does not exist");
break;
case 4 :
System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(cur,accno,j);
if(pos<0)
{
System.out.println("Account does not exist");
break;
}
System.out.println("Enter the amount to be deposited");
amt = scan.nextInt() ;
cur[pos].deposit(amt); break;
case 5 :
System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(save,accno,i);
if(pos>=0)
{
System.out.println("Enter the withdrawl amount ");
amt = scan.nextInt() ;
save[pos].withdraw(amt);
}
else
System.out.println("Account does not exist");
break;
case 6 :
System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(cur,accno,j);
if(pos<0)
{
System.out.println("Account does not exist");
break;
}
System.out.println("Enter the withdrawl amount ");
amt = scan.nextInt() ;
cur[pos].withdraw(amt); break;
case 7: System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(save,accno,i);
if(pos>=0)
save[pos].showBalance();
else
System.out.println("Account does not exist");
break;
case 8: System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(cur,accno,j);
if(pos<0)
{
System.out.println("Account does not exist");
break;
}
cur[pos].showBalance(); break;
case 9: System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(save,accno,i);
if(pos>=0)
save[pos].showDetails();
else
System.out.println("Account does not exist");
break;
case 10: System.out.println("Enter the account no");
accno = scan.nextInt() ;
pos = search(cur,accno,j);
if(pos>=0)
cur[pos].showDetails();
else
System.out.println("Account does not exist");
break;
case 11: System.out.println("Bank Software Closed");System.exit(1);
default : System.out.println("Wrong Entry \n ");
}
System.out.println("\nDo you want to continue (Type y or n) \n");
ch = scan.next().charAt(0); // will give the first character of entered string
} while (ch == 'Y'|| ch == 'y');
}
}