-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbankacc.java
More file actions
171 lines (150 loc) · 6.02 KB
/
bankacc.java
File metadata and controls
171 lines (150 loc) · 6.02 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
import java.util.Scanner;
abstract class GeneralAccount {
int accNo;
String accHolderName;
double accBalance;
protected GeneralAccount(int accNo, String accHolderName, double accBalance) {
this.accNo = accNo;
this.accHolderName = accHolderName;
this.accBalance = accBalance;
}
public int getAccNo() {
return accNo;
}
public void setAccNo(int accNo) {
this.accNo = accNo;
}
public String getAccHolderName() {
return accHolderName;
}
public void setAccHolderName(String accHolderName) {
this.accHolderName = accHolderName;
}
public double getAccBalance() {
return accBalance;
}
@Override
public String toString() {
return "\nDeatils: \nAccount Number=" + accNo + "\nAccount Holder Name=" + accHolderName + ",\nAccount Balance=" + accBalance;
}
GeneralAccount clone(GeneralAccount ac) {
return ac;
}
public void additionalFeatures() {
}
GeneralAccount getStatement() {
return this;
}
void getAccountDetails() {
System.out.println("Account holder name : "+this.accHolderName+"\nAccount type : "+this.getClass().getName());
}
}
class savingsAccounts extends GeneralAccount {
static final double roi = 3.2 ;
public savingsAccounts(int accNo, String accHolderName, double accBalance) {
super(accNo, accHolderName, accBalance);
}
public double getRoi() {
return roi;
}
double getYearlyInterset() {
return roi * accBalance/100;
}
double getComputeYearlyInterset(int years) {
return years * getYearlyInterset() / 100;
}
}
class currentAccounts extends GeneralAccount {
double avgDailyTransation;
public currentAccounts(int accNo, String accHolderName,double accBalance) {
super(accNo, accHolderName, accBalance);
}
public double getAvgDailyTransation() {
return avgDailyTransation;
}
public void setAvgDailyTransation(double avgDailyTransation) {
this.avgDailyTransation = avgDailyTransation;
}
double getYearlytransation() {
return avgDailyTransation*(12*30);
}
double getTotalTransation(int days) {
return avgDailyTransation * days;
}
}
public class bankacc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no of accounts to create: ");
int n = sc.nextInt();
sc.nextLine();
GeneralAccount[] generalAcc = new GeneralAccount[n];
java.util.Arrays.sort(generalAcc);
savingsAccounts[] savingAcc = new savingsAccounts[n];
currentAccounts[] currentAcc = new currentAccounts[n];
GeneralAccount[] salaryAcc = new GeneralAccount[n];
for (int i = 0; i < n; i++) {
System.out.println("Enter the salary account name for account no. " + (i+1) + ":\nEnter name:");
salaryAcc[i] = new GeneralAccount(i+1,sc.nextLine(),60000) {
double salary;
double pf;
double incomeTaxRate = 10 / 100;
public double getYearlyTax(){
return (salary * incomeTaxRate);
}
public double getInHandSalary() {
return salary - (pf + getYearlyTax());
}
@Override
public void additionalFeatures() {
getYearlyTax();
getInHandSalary();
}
@Override
void getAccountDetails() {
System.out.println("Account Holder name : " + this.accHolderName + "\nAccount type : Salary Account.");
}
};
}
// for (int i = 0; i < n; i++) {
// System.out.print("Enter the general account name for account no. " + (i+1) + ":\nEnter name:");
// generalAcc[i] = new GeneralAccount((i + 1),sc.nextLine(),60000);
// }
for (int i = 0; i < n; i++) {
System.out.print("Enter the saving account name for account no. " + (i+1) + ":\nEnter name:");
savingAcc[i] = new savingsAccounts((i + 1),sc.nextLine(),20000);
}
for (int i = 0; i < n; i++) {
System.out.print("Enter the current account name for account no. " + (i + 1) + ":\nEnter name:");
currentAcc[i] = new currentAccounts((i + 1), sc.nextLine(),90000);
}
System.out.println();
// for (int i = 0; i < n ; i++ )
// System.out.print("Details for general account no. " + (i + 1) + ": " + generalAcc[i] + "\n");
// System.out.println();
for (int i = 0; i < n ; i++ )
System.out.print("Details for saving account no. " + (i + 1)+ ": " + savingAcc[i] + "\n");
System.out.println();
for (int i = 0; i < n ; i++ )
System.out.print("Details for current account no. " +(i + 1) + ": " + currentAcc[i] + "\n");
System.out.println();
for (int i = 0; i < n ; i++ )
System.out.print("Details for salary account no. " +(i + 1) + ": " + salaryAcc[i] + "\n");
sc.close();
// GeneralAccount clonedAcc = new GeneralAccount();
// clonedAcc = clonedAcc.clone(salaryAcc[0]);
// System.out.println("Cloned account:" + clonedAcc);
System.out.println("\n------ After Modification ------\n");//\nStatement of generalAccount\n"
//+ generalAcc[0].getStatement()+"\n");
//(generalAcc[0].getStatement()).getAccountDetails();
System.out.println("\nStatement of savingsAccount\n"
+ savingAcc[0].getStatement()+"\n");
(savingAcc[0].getStatement()).getAccountDetails();
System.out.println("\nStatement of currentAccount\n"
+ savingAcc[0].getStatement()+"\n");
(savingAcc[0].getStatement()).getAccountDetails();
System.out.println("\nStatement of salaryAccount\n"
+ salaryAcc[0].getStatement()+"\n");
(salaryAcc[0].getStatement()).getAccountDetails();
}
}