UID:18BCS2051 Subject: Project Based Learning in Java Practical No.3
UID:18BCS2051 Subject: Project Based Learning in Java Practical No.3
Practical No.3
Calculate interest based on the type of the account and the status of the account holder.
The rates of interest changes according to the amount (greater than or less than 1 crore),
age of account holder (General or Senior citizen) and number of days if the type of account
is FD or RD.
Program Code:
package acc;
import java.util.*;
abstract class acc{
double interest;
double amount;
double interestAmount;
protected abstract double calculateInterest();
}
class FDAccount extends acc{
private int noOfDays;
private int ageOfACHolder;
FDAccount(int am,int days,int age){
amount = am;
noOfDays = days;
ageOfACHolder = age;
}
@Override
protected double calculateInterest() {
if (amount < 10000000) {
if(ageOfACHolder < 65) {
}
}
else {
if(noOfDays >= 7 && noOfDays <= 14) {
interest = 6.50;
}
else if(noOfDays >= 15 && noOfDays <= 29) {
interest = 6.75;
}
else if(noOfDays >= 30 && noOfDays <= 45) {
interest = 6.75;
}
else if(noOfDays >= 46 && noOfDays <= 60) {
interest = 8.00;
}
else if(noOfDays >= 61 && noOfDays <= 184) {
interest = 8.50;
}
else if(noOfDays >= 185 && noOfDays <= 365) {
interest = 10.00;
}
}
class SBAccount extends acc{
SBAccount(int am){
amount = am;
}
@Override
protected double calculateInterest() {
interest= 4.0;
interestAmount =interest * amount/100;
return interestAmount;
}
}
class RDAccount extends acc{
int noOfMonths;
double monthlyAmount;
private int ageOfACHolder;
RDAccount( int am, int months, int age){
monthlyAmount = am;
ageOfACHolder = age;
noOfMonths = months;
}
@Override
protected double calculateInterest() {
if(ageOfACHolder < 65) {
}
interestAmount = 0;
for(int i = 0;i < interest;i++) {
interestAmount += interest * monthlyAmount/100;
}
return interestAmount;
}
}
public class account {
switch(n)
{
case 1:
{
}
sc.close();
}
}
Output Window:
1. SB:
2. FD(Senior Citizen):
3. FD(General Citizen):
4. FD(invalid days):
5. RD(Senior Citizen):
6. RD(General Citizen):
7. Exit: