-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExp03.java
320 lines (270 loc) · 5.99 KB
/
Exp03.java
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
import java.util.*;
class Account
{
String name;
int ac_no;
char ac_type;
float balance = 1000;
public void input()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Your Name:");
name = sc.nextLine();
System.out.println("Enter Account Number:");
ac_no = sc.nextInt();
System.out.println("Enter Account Type (s/c):");
ac_type=sc.next().charAt(0);
}
float getBalance()
{
return (this.balance);
}
}
class Current extends Account
{
float min_bal, penalty, deposit, withdraw;
float balance = getBalance();
Current()
{
min_bal = 1000;
penalty = 500;
}
public void deposit()
{
Scanner sc = new Scanner(System.in);
System.out.println("\nEnter amount to deposit");
deposit = sc.nextFloat();
balance = balance + deposit;
System.out.println("\nThe new balance is Rs."+balance+"\n");
}
public void minimumBalance()
{
if(balance < min_bal)
{
System.out.println("\nThe balance in your account is less than the minimum balance required");
System.out.println("You will be charged a penalty of Rs. "+penalty);
balance=balance-penalty;
System.out.println("The new balance is Rs."+balance);
}
else
System.out.println("\nSufficient Balance Present\n");
}
public void withdraw()
{
Scanner sc = new Scanner(System.in);
System.out.println("\nEnter amount to be withdrawn");
withdraw = sc.nextFloat();
if(balance > withdraw)
balance = balance - withdraw;
else
System.out.println("Insufficient Balance");
System.out.println("Your balance is Rs."+balance+"\n");
}
public void chequeBook()
{
Scanner sc = new Scanner(System.in);
System.out.println("\nDo you want a Cheque Book? (Yes/No)");
if(sc.nextLine().equalsIgnoreCase("yes"))
{
System.out.println("Enter the number of cheques (25/50)");
int cheque_no = sc.nextInt();
if( (cheque_no == 25) || (cheque_no == 50) )
System.out.println("A cheque book containing "+cheque_no+" cheques will be soon issued to you\n");
else
System.out.println("Invalid Number of Cheques\n");
}
}
}
class Savings extends Account
{
float deposit, withdraw;
int r, n;
float balance = getBalance();
Savings()
{
r=10;
n=1;
}
public void deposit()
{
Scanner sc = new Scanner(System.in);
System.out.println("\nEnter amount to deposit");
deposit = sc.nextFloat();
balance = balance + deposit;
System.out.println("The new balance is Rs."+balance+"\n");
}
public void compoundInterest()
{
double r = 10, n = 1;
double compound_interest, amount;
compound_interest = Math.pow( (1 + (r / 100)), n);
amount = balance * compound_interest;
System.out.println("\nAmount available with interest is Rs."+amount+"\n");
}
public void withdraw()
{
Scanner sc = new Scanner(System.in);
System.out.println("\nEnter amount to be withdrawn");
withdraw = sc.nextFloat();
if(balance > withdraw)
balance = balance - withdraw;
else
System.out.println("Insufficient Balance");
System.out.println("Your balance is Rs."+balance+"\n");
}
}
class Exp03
{
public static void main(String[] args)
{
Account a = new Account();
a.input();
if(a.ac_type == 's')
{
Savings s = new Savings();
int i;
do
{
System.out.println("\n1.Deposit Amount\n2.Find Interest\n3.Withdraw Amount\n4.Exit");
System.out.println("\nEnter Your Choice");
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
switch(i)
{
case 1:
s.deposit();
break;
case 2:
s.compoundInterest();
break;
case 3:
s.withdraw();
break;
}
}while(i != 4);
}
else if(a.ac_type == 'c')
{
Current c = new Current();
int j;
do
{
System.out.println("\n1.Deposit Amount\n2.Withdraw Amount\n3.Check Minimum Balance\n4.Issue Cheque Book\n5.Exit");
System.out.println("Enter Your Choice");
Scanner sc = new Scanner(System.in);
j = sc.nextInt();
switch(j)
{
case 1:
c.deposit();
break;
case 2:
c.withdraw();
break;
case 3:
c.minimumBalance();
break;
case 4:
c.chequeBook();
break;
}
}while(j != 5);
}
else
System.out.println("Invalid Choice");
}
}
/* OUTPUT - 1
*
*Enter Your Name:
Jimit
Enter Account Number:
100596
Enter Account Type (s/c):
s
1.Deposit Amount
2.Find Interest
3.Withdraw Amount
4.Exit
Enter Your Choice
1
Enter amount to deposit
100
The new balance is Rs.1100.0
1.Deposit Amount
2.Find Interest
3.Withdraw Amount
4.Exit
Enter Your Choice
2
Amount available with interest is Rs.1210.0
1.Deposit Amount
2.Find Interest
3.Withdraw Amount
4.Exit
Enter Your Choice
3
Enter amount to be withdrawn
150
Your balance is Rs.950.0
1.Deposit Amount
2.Find Interest
3.Withdraw Amount
4.Exit
Enter Your Choice
4 */
/* OUTPUT - 2
*
*Enter Your Name:
Jimit
Enter Account Number:
100596
Enter Account Type (s/c):
c
1.Deposit Amount
2.Withdraw Amount
3.Check Minimum Balance
4.Issue Cheque Book
5.Exit
Enter Your Choice
1
Enter amount to deposit
200
The new balance is Rs.1200.0
1.Deposit Amount
2.Withdraw Amount
3.Check Minimum Balance
4.Issue Cheque Book
5.Exit
Enter Your Choice
2
Enter amount to be withdrawn
100
Your balance is Rs.1100.0
1.Deposit Amount
2.Withdraw Amount
3.Check Minimum Balance
4.Issue Cheque Book
5.Exit
Enter Your Choice
3
Sufficient Balance Present
1.Deposit Amount
2.Withdraw Amount
3.Check Minimum Balance
4.Issue Cheque Book
5.Exit
Enter Your Choice
4
Do you want a Cheque Book? (Yes/No)
yes
Enter the number of cheques (25/50)
25
A cheque book containing 25 cheques will be soon issued to you
1.Deposit Amount
2.Withdraw Amount
3.Check Minimum Balance
4.Issue Cheque Book
5.Exit
Enter Your Choice
5 */