PBLJ 1.3
PBLJ 1.3
Question :
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 :
importjava.util.*;
abstractclassaccount{
doubleinterestRate,amount;
abstractdoublecalculateinterest(doubleamount)throwsmyException;
classFDAccountextends account{
sCitizen=1;intnoOfDays, age;
doublecalculateinterest(doubleamount)throwsmyException{t
his.amount=amount;
Scanner s = new
Scanner(System.in);System.out.printl
n("EnterNumberOfDays:");noOfDay
s= s.nextInt();
if(noOfDays<0){
thrownewmyException("DaysShouldbeGreaterthan0.");
else{
System.out.println("Ënte
rAge:");age =s.nextInt();
if(age<0){
thrownewmyException("Agemustbegreaterthan0.");
}
else{if(amount<10
000000){
if(noOfDays>=7 &&
noOfDays<=14)
{general= 5.50;
sCitizen=6.00;
}
else if(noOfDays>=15 &&
noOfDays<=29){general=
4.75;
sCitizen=5.25;
}
else if(noOfDays>=30 &&
noOfDays<=45){general=
5.50;
sCitizen=6.00;
}
else if(noOfDays>=45 &&
noOfDays<=60){general=
7.00;
sCitizen=7.50;
}
else if(noOfDays>=61 &&
noOfDays<=184){general=
7.50;
sCitizen=8.00;
}
else if(noOfDays>=185 &&
noOfDays<=365){general= 8.00;
sCitizen=8.50;
}
}
else{
if(noOfDays>=7 &&
noOfDays<=14)
{interestRate =6.50;
}
else if(noOfDays>=15 &&
noOfDays<=29){interestRate
=6.750;
}
else if(noOfDays>=30 &&
noOfDays<=45){interestRate
=6.75;
noOfDays<=60){interestRate
=8;
noOfDays<=184){interestRate
=8.50;
}
else if(noOfDays>=185 &&
noOfDays<=365){interestRate
=10.00;
interestRate = (age<50)?general :
sCitizen;returninterest =amount
*interestRate;
}
classSBAccountextendsaccount
{doubleinterest,interestRate,a
mount;
doublecalculateinterest(doubleamount)throwsmyException{t
his.amount=amount;
System.out.println("SelectAccountType:\n1.Normal\
intchoice=s.nextInt();
switch(choice){
case 1: interestRate
= 0.04;break;
case 2: interestRate
= 0.06;break;
default:System.out.println("WrongChoice.");
returnamount*interestRate;
classRDAccountextendsaccount{
doubleinterest,interestRate,amount,monthlyAmount,general=1,sCitiz
en=1;intnoOfMonths, age;
doublecalculateinterest(doubleamount)throwsmyException{t
his.amount=amount;
Scanner s = new
Scanner(System.in);System.out.println(
"EnterNumberOfMonths:");noOfMonth
s= s.nextInt();
if(noOfMonths<0){
thrownewmyException("Monthsshouldbegreaterthan0.");
else{
System.out.println("Ënte
rAge:");age =s.nextInt();
if(age<0){
thrownewmyException("Ageshouldbegreaterthan0.");
else{
if(noOfMonths==6){
general=5.50;
sCitizen=6.00;
else
if(noOfMonths
== 9){general=
4.75;
sCitizen=5.25;
else
if(noOfMonths
== 12){general=
5.50;
sCitizen=6.00;
}
else
if(noOfMonths
== 15){general=
7.00;
sCitizen=7.50;
elseif(noOfMonths==18){
general=7.50;
sCitizen=8.00;
else
if(noOfMonths
== 21){general=
8.00;
sCitizen=8.50;
interestRate = (age<50)?general :
sCitizen;returninterest=amount*
interestRate;
}
publicstaticvoidmain(String[
]args){intt =4,choice;
doubleamount;
Scanners=newScanner(Syst
em.in);do{
System.out.println("SelectTheOption:\n1.InterestCalculator-SB\n2.InterestCalculator-
FD\n"
switch(choice){
SBAccount();System.out.pri
ntln("Enter Amount:
");amount= s.nextInt();
try{
System.out.println("Interest:"+ob1.calculateinterest(amount));
}
catch (Exception m)
{System.out.println("Exceptionoccu
red:"+m);
break;
FDAccount();System.out.pri
ntln("Enter Amount:
");amount= s.nextInt();
try{
System.out.println("Interest:"+ob2.calculateinterest(amount));
catch (Exception m)
{System.out.println("Exceptionoccu
red:"+m);
break;
case3:RDAccountob3=newRDAccount();
System.out.println("Enter
Amount: ");amount=
s.nextInt();
try{
System.out.println("Interest:"+ob3.calculateinterest(amount));
catch (Exception m)
{System.out.println("Exceptionoccu
red:"+m);
break;
case4:System.exit(t);
default:
System.out.println("WrongChoice:");
t--
;
}while(t!=0);
}
}
Option -2
Enter the FD amount : 10000
Enter the number of days : 91
Enter your age : 65
Interest gained is : 800
Option -2
Enter the FD amount : 10000
Enter the number of days : 91
Enter your age : 34
Interest gained is : 750
Option - 2
Enter the FD amount : 10000
Enter the number of days : -7
Enter your age : 78
Invalid Number of days. Please enter correct values.