-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankCustomer.java
215 lines (185 loc) · 5.16 KB
/
BankCustomer.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
import java.util.Scanner;
class Account { // parent class
Scanner sc = new Scanner(System.in);
// data members of Account class
String name; // name of account holder
int accno; // account number
String type; // type of account
double bal; // balance
// method to get user details
void Input() {
System.out.println("Enter name::");
name = sc.nextLine();
System.out.println("Enter Account number:: ");
accno = sc.nextInt();
sc.nextLine();
System.out.println("Enter type of account:: ");
type = sc.nextLine();
System.out.println("Enter Principal amount:: ");
bal = sc.nextDouble();
}
// method to display user info
void Display() {
System.out.println("________________________________________________________________");
System.out.println("Name:: " + name);
System.out.println("Account No:: " + accno);
System.out.println("Type:: " + type);
System.out.println("Balance:: " + bal);
System.out.println("_________________________________________________________________");
}
// method to deposit money
void Deposit() {
double amt;
System.out.println("Enter the amount to be depositedt:: ");
amt = sc.nextDouble();
bal = bal + amt; // balance will be added in principal amount
}
}
class Savings extends Account { // Saving is subclass derived from Account
double interest;
void compInterest() { // method to calculate compound interest
int time;
double rate;
System.out.println("Enter duration (in years):: "); // duration in year
time = sc.nextInt();
System.out.println("Enter annual interest rate:: "); // interest rate
rate = sc.nextDouble();
interest = bal * Math.pow(1 + rate / 100, time) - bal; // compound interest formula
System.out.println("The coumpount interest will be " + interest);
}
void withdrawal() { // method to withdraw money
double amount;
System.out.println("Enter the amount to be withdrawn:: ");
amount = sc.nextDouble();
if (bal >= amount) {
bal = bal - amount; // balance will be reduced by money withdrawn
} else {
System.out.println("The amount cannot be withdrawn!!");
}
}
}
class Current extends Account { // Current is Subclass derived from Account
double penalty;
int minBal() {
int ret1 = 1;
if (bal <= 10000) {
// if minimum balance in current account is less than 10,000 than penalty will
// be imposed
penalty = 2500;
// penalty of 2,500 will be imposed for not maintaining minimum balance
bal = bal - penalty;
ret1 = 0;
} else {
System.out.println("No penalty imposed");
}
return ret1;
}
// method to withdraw money
void withdrawal() {
double amt;
System.out.println("Enter the amount to withdraw");// withdrawl amount
amt = sc.nextDouble();
int k = minBal();
if (k == 1) {
if (bal >= amt)
bal = bal - amt;
} else {
System.out.println("The amount cannot be withdrawn");
// if balance is less than amount to be withdrawn
}
}
// method to deposit check
void deposit_check() {
System.out.println("Enter check amount");
double check_amt = sc.nextDouble();
bal = bal + check_amt;
System.out.println("Your cheque has been deposited and current balance becomes: " + bal);
}
}
public class BankCustomer {
public static void main(String[] args) {
// TODO Auto-generated method stub
int ch1, ch2;
Scanner s1 = new Scanner(System.in);
System.out.println("---Enter the account type---");
System.out.println("1. Savings\n2. Current");
ch1 = s1.nextInt();
if (ch1 == 1) {
Savings s = new Savings(); // object creation of savings class
s.Input();
int x = 1;
do {
System.out.println("_______________________________");
System.out.println(
"1. Deposit\n2. Display Balance\n3. Calculate Compound interest\n4. Withdrawl\n5. Exit");
System.out.println("________________________________");
ch2 = s1.nextInt();
switch (ch2) {
case 1:
// deposit method called
s.Deposit();
// display method called
s.Display();
break;
case 2:
// display method called
s.Display();
break;
case 3:
// interest calculate method called
s.compInterest();
break;
case 4:
// withdrawl method called
s.withdrawal();
s.Display();
break;
case 5:
x = 0;
break;
default:
System.out.println("Invalid choice");
}
} while (x == 1);
} else if (ch1 == 2) {
Current c = new Current();
c.Input();
int x = 1;
do {
System.out.println("______________________________");
System.out.println("1. Deposit\n2. Display Balance\n3. Withdrawl\n4. Deposit Chequebook\n5. Exit");
System.out.println("_______________________________");
ch2 = s1.nextInt();
switch (ch2) {
case 1:
// deposit method called
c.Deposit();
c.Display();
break;
case 2:
// display method called
c.Display();
break;
case 3:
// withdrawl method called
c.withdrawal();
c.Display();
break;
case 4:
// deposit check method called
c.deposit_check();
c.Display();
break;
case 5:
x = 0;
break;
default:
System.out.println("Invalid choice");
}
} while (x == 1);
}
else {
System.out.println("Invalid choice");
}
}
}