-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
239 lines (190 loc) · 7.17 KB
/
Bank.java
File metadata and controls
239 lines (190 loc) · 7.17 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
import java.util.Scanner;
class BankAccount {
static int count = 1;
int accNo;
private double accBalance;
private String accHolderName;
public BankAccount(String accHolderName) {
this.accNo = count;
count++;
this.accHolderName = accHolderName;
}
public BankAccount(String accHolderName, double accBalance) {
this(accHolderName);
this.accBalance = accBalance;
}
public BankAccount(BankAccount account) {
this.accNo = account.accNo;
this.accHolderName = account.accHolderName;
this.accBalance = account.accBalance;
}
public int getAccNo() {
return accNo;
}
public double getAccBalance() {
return accBalance;
}
public void setAccBalance(double accBalance) {
this.accBalance = accBalance;
}
public String getAccHolderName() {
return accHolderName;
}
public void setAccHolderName(String accHolderName) {
this.accHolderName = accHolderName;
}
@Override
public String toString() {
return "accNo : " + accNo + "\naccHolderName : " + accHolderName +
"\naccBalance : " + accBalance + "\n";
}
public static BankAccount copy(BankAccount acc) {
return new BankAccount(acc);
}
public BankAccount getStatement() {
System.out.println(
"Account Holder : " + this.accHolderName + "\nAccount Type : " + this.getClass().getName() + "\n");
return this;
}
}
class SavingAccount extends BankAccount {
static double rateOfIntrest;
public SavingAccount(String accHolderName) {
super(accHolderName);
this.setAccHolderName(accHolderName);
}
public SavingAccount(String accHolderName, double accBalance) {
super(accHolderName, accBalance);
}
public double getRateOfIntrest() {
return rateOfIntrest;
}
public static void setRateOfIntrest(double roi) {
rateOfIntrest = roi;
}
@Override
public String toString() {
return "Savings Account :-\n" + super.toString();
}
double getYearlyInterest() {
return (this.getAccBalance() * rateOfIntrest / 100);
}
double getComputedInterest(int years) {
return this.getYearlyInterest() * years;
}
@Override
public SavingAccount getStatement() {
System.out.println(
"Account Holder : " + this.getAccHolderName() + "\nAccount Type : " + this.getClass().getName() + "\n");
return this;
}
}
class CurrentAccount extends BankAccount {
double avgDailyTransaction;
public CurrentAccount(String accHolderName) {
super(accHolderName);
}
public CurrentAccount(String accHolderName, double accBalance) {
super(accHolderName, accBalance);
}
public CurrentAccount(double avgDailyTransaction, String accHolderName) {
super(accHolderName);
this.avgDailyTransaction = avgDailyTransaction;
}
public CurrentAccount(double avgDailyTransaction, String accHolderName,
double accBalance) {
super(accHolderName, accBalance);
this.avgDailyTransaction = avgDailyTransaction;
}
public double getAvgDailyTransaction() {
return avgDailyTransaction;
}
public void setAvgDailyTransaction(double avgDailyTransaction) {
this.avgDailyTransaction = avgDailyTransaction;
}
@Override
public String toString() {
return "Current Account :-\n" + super.toString() + "avgDailyTransaction : " +
this.avgDailyTransaction + "\n";
}
double getTotalTransactionAmount(int days) {
return avgDailyTransaction * days;
}
double getYearlyTransaction() {
return getTotalTransactionAmount(365);
}
@Override
public CurrentAccount getStatement() {
System.out.println(
"Account Holder : " + this.getAccHolderName() + "\nAccount Type : " + this.getClass().getName() + "\n");
return this;
}
}
public class Bank {
public static void classesDemos() {
BankAccount generalAcc = new BankAccount("Lalit");
System.out.println(generalAcc);
SavingAccount savingsAcc = new SavingAccount("Yusuf");
System.out.println(savingsAcc);
SavingAccount.setRateOfIntrest(3.4);
savingsAcc.setAccBalance(20000);
System.out.println("getYearlyIntrest : " + savingsAcc.getYearlyInterest());
System.out.println("getComputedInterest of 3 years : " +
savingsAcc.getComputedInterest(3) + "\n");
CurrentAccount currentAcc = new CurrentAccount(3, "Bheru", 1200.50);
currentAcc.setAvgDailyTransaction(400);
System.out.println(currentAcc);
System.out.println("getYearlyTransaction : " +
currentAcc.getYearlyTransaction());
System.out.println("getTotalTransactionAmount of 10 days : " +
currentAcc.getTotalTransactionAmount(10) + "\n");
}
public static BankAccount salaryAccount(String name) {
return new BankAccount(name) {
double salary = 50000;
double pfAmount = 6000;
double incomeTaxRate = 5.5;
double getYearlyTax() {
return salary * incomeTaxRate * 12 / 100;
}
double getInHandSalary() {
return (salary - getYearlyTax() / 12 - pfAmount);
}
@Override
public String toString() {
return super.toString() + "salary : " + this.salary + ", pfAmount : " +
this.pfAmount + "\n Yearly Tax : " + getYearlyTax() + "\nIn Hand Salary(Monthly) : "
+ getInHandSalary() + "\n";
}
};
}
public static void accountArraysAndCopy() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter no. of Accounts you wanna Create : ");
int n = scanner.nextInt();
SavingAccount[] savingsArray = new SavingAccount[n];
CurrentAccount[] currentArray = new CurrentAccount[n];
BankAccount[] salaryArray = new BankAccount[n];
for (int i = 0; i < n; i++) {
savingsArray[i] = new SavingAccount("saving " + (i + 1), 20000.0 * i);
currentArray[i] = new CurrentAccount("current " + (i + 1));
salaryArray[i] = salaryAccount("Salary " + (i + 1));
System.out.println(savingsArray[i]);
System.out.println(currentArray[i]);
System.out.println(salaryArray[i]);
}
BankAccount copySavingAccount = new BankAccount(savingsArray[0]);
System.out.println("Copy Account -\n" + copySavingAccount);
BankAccount copyCurrentAccount = BankAccount.copy(currentArray[0]);
System.out.println("Copy Account -\n" + copyCurrentAccount);
scanner.close();
}
public static void main(String[] args) {
BankAccount generalAcc = new BankAccount("Lalit");
generalAcc.getStatement();
SavingAccount savingsAcc = new SavingAccount("Yusuf");
System.out.println(savingsAcc.getStatement());
CurrentAccount currentAcc = new CurrentAccount(3, "Bheru", 1200.50);
System.out.println(currentAcc.getStatement());
}
}