-
Notifications
You must be signed in to change notification settings - Fork 360
/
Create an application to calculate interest for FD’s , RD’s based on certain conditions
224 lines (193 loc) · 5.86 KB
/
Create an application to calculate interest for FD’s , RD’s based on certain conditions
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
package Anmol;
import java.util.Scanner;
public class InterestCalculator {
public static void main(String[] args) {
Scanner sc = newScanner(System.in);
System.out.println("SELECT THE OPTIONS " + "\n1." + " Interest Calculator-SB" + " \n2." + " Interest Calculator-FD" + "\n3." + " InterestCalculator-RD" + "\n4 " + " Exit");
intchoice = sc.nextInt();
switch (choice) {
case 1:
SBaccountsb = newSBaccount();
try {
System.out.println("Enter the Average SB amount ");
Double amount = sc.nextDouble();
System.out.println("Interest gained is : Rs " + sb.calculateInterest(amount));
} catch (InvalidAmountExceptione) {
System.out.println("Exception : Invalid amount");
}
break;
case 2:
try {
FDaccountfd = newFDaccount();
System.out.println("Enter the FD Amount");
doublefAmount = sc.nextDouble();
System.out.println("Interest gained is: Rs " + fd.calculateInterest(fAmount));
} catch (InvalidAgeExceptione) {
System.out.println("Invalid Age Entered");
} catch (InvalidAmountExceptione) {
System.out.println("Invalid Amount Entered");
} catch (InvalidDaysExceptione) {
System.out.println("Invalid Days Entered");
}
break;
case 3:
try {
RDaccountrd = newRDaccount();
System.out.println("Enter the RD amount");
doubleRamount = sc.nextDouble();
System.out.println("Interest gained is: Rs " + rd.calculateInterest(Ramount));
}
catch (InvalidAgeExceptione) {
System.out.println("Invalid Age Entered");
} catch (InvalidAmountExceptione) {
System.out.println("Invalid Amount Entered");
} catch (InvalidMonthsExceptione) {
System.out.println("Invalid Days Entered");
}
break;
case 4:
System.out.println("DO YOU WANT TO CALCULATE AGAIN ????" + " "
+ "RUN AGAIN THE PROGRAM");
default:
System.out.println("Wrong choice");
}
sc.close();
}
}
abstractclass Account {
double interestRate;
double amount;
abstractdouble calculateInterest (doubleamount) throws InvalidMonthsException,InvalidAgeException,InvalidAmountException ,InvalidDaysException;
}
Class FDaccount extends Account {
Double FDinterestRate;
Double FDAmount;
Int noOfDays;
Int ageOfACHolder;
Double General, SCitizen;
Scanner FDScanner = newScanner(System.in);
Double calculateInterest(doubleamount) throws InvalidAgeException,InvalidAmountException,InvalidDaysException {
this.FDAmount = amount;
System.out.println("Enter FD days");
noOfDays = FDScanner.nextInt();
System.out.println("Enter FD age holder ");
ageOfACHolder = FDScanner.nextInt();
if (amount< 0) {
thrownewInvalidAmountException();
}
if(noOfDays<0){
thrownewInvalidDaysException();
}
if(ageOfACHolder<0){
thrownewInvalidAgeException();
}
if (amount< 10000000) {
if (noOfDays>= 7 &&noOfDays<= 14) {
General = 0.0450;
SCitizen = 0.0500; }
elseif (noOfDays>= 15 &&noOfDays<= 29) {
General = 0.0470;
SCitizen = 0.0525;
} elseif (noOfDays>= 30 &&noOfDays<= 45) {
General = 0.0550;
SCitizen = 0.0600;
} elseif (noOfDays>= 45 &&noOfDays<= 60) {
General = 0.0700;
SCitizen = 0.0750;
} elseif (noOfDays>= 61 &&noOfDays<= 184) {
General = 0.0750;
SCitizen = 0.0800;
} elseif (noOfDays>= 185 &&noOfDays<= 365) {
General = 0.0800;
SCitizen = 0.0850;
}
FDinterestRate = (ageOfACHolder< 50) ?General :SCitizen;
} else {
if (noOfDays>= 7 &&noOfDays<= 14) {
interestRate = 0.065;
} elseif (noOfDays>= 15 &&noOfDays<= 29) {
interestRate = 0.0675;
} elseif (noOfDays>= 30 &&noOfDays<= 45) {
interestRate = 0.00675;
} elseif (noOfDays>= 45 &&noOfDays<= 60) {
interestRate = 0.080;
} elseif (noOfDays>= 61 &&noOfDays<= 184) {
interestRate = 0.0850;
} elseif (noOfDays>= 185 &&noOfDays<= 365) {
interestRate = 0.10;
}
}
returnFDAmount * FDinterestRate;
}
}
classInvalidAgeExceptionextendsException{}
classInvalidAmountExceptionextendsException{}
classInvalidDaysExceptionextendsException{}
classInvalidMonthsExceptionextendsException{}
classRDaccountextends Account {
doubleRDInterestRate;
doubleRDamount;
intnoOfMonths;
doublemonthlyAmount;
doubleGeneral, SCitizen;
Scanner RDScanner = newScanner(System.in);
doublecalculateInterest(doubleRamount) throwsInvalidMonthsException,InvalidAmountException ,InvalidAgeException {
this.RDamount = Ramount;
System.out.println("Enter RD months");
noOfMonths = RDScanner.nextInt();
System.out.println("Enter RD holder age");
intage = RDScanner.nextInt();
if (RDamount< 0) {
thrownewInvalidAmountException();
}
if(noOfMonths<0){
thrownewInvalidMonthsException();
}
if(age<0){
thrownewInvalidAgeException();
}
if (noOfMonths>= 0 &&noOfMonths<= 6) {
General = .0750;
SCitizen = 0.080;
} elseif (noOfMonths>= 7 &&noOfMonths<= 9) {
General = .0775;
SCitizen = 0.0825;
} elseif (noOfMonths>= 10 &&noOfMonths<= 12) {
General = .0800;
SCitizen = 0.0850;
} elseif (noOfMonths>= 13 &&noOfMonths<= 15) {
General = .0825;
SCitizen = 0.0875;
} elseif (noOfMonths>= 16 &&noOfMonths<= 18) {
General = .0850;
SCitizen = 0.0900;
} elseif (noOfMonths>= 22) {
General = .0875;
SCitizen = 0.0925;
}
RDInterestRate = (age< 50) ?General :SCitizen;
returnRDamount * RDInterestRate;
}
}
classSBaccountextends Account {
doubleSBamount ,SbInterestRate, interest;
Scanner SBScanner = newScanner(System.in);
Double calculateInterest(double amount) throws Invalid AmountException{
this.SBamount = amount;
if(SBamount< 0 ){
thrownew Invalid AmountException();
}
System.out.println("Select account type \n1. NRI \n2. Normal ");
Int account Choice = SBScanner.nextInt();
switch (account Choice) {
case 1:
SbInterestRate = .06;
break;
case 2:
SbInterestRate = .04;
break;
default:
System.out.println("Please choose right account again");
}
return amount * SbInterestRate;
}}