0% found this document useful (0 votes)
33 views16 pages

PBLJ 1.3

The program calculates interest on bank accounts based on account type (fixed deposit, recurring deposit, or savings), account amount, number of days/months, and customer age and citizenship status. It handles different interest rates for amounts over and under 1 crore, as well as rates for general customers and senior citizens. The user can select the account type and enter relevant details to calculate interest, with exceptions thrown for invalid inputs like negative numbers.

Uploaded by

Abhishek Pundir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views16 pages

PBLJ 1.3

The program calculates interest on bank accounts based on account type (fixed deposit, recurring deposit, or savings), account amount, number of days/months, and customer age and citizenship status. It handles different interest rates for amounts over and under 1 crore, as well as rates for general customers and senior citizens. The user can select the account type and enter relevant details to calculate interest, with exceptions thrown for invalid inputs like negative numbers.

Uploaded by

Abhishek Pundir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

WORKSHEET-1.

Student Name: Ankit Jha UID: 20BCS9637

Branch: BE-CSE Section/Group: 705/A

Semester: 5th Subject: JAVA Lab

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.*;

class myException extends Exception{myException(Strings){


super(s);

abstractclassaccount{

doubleinterestRate,amount;

abstractdoublecalculateinterest(doubleamount)throwsmyException;

classFDAccountextends account{

double interest, interestRate, amount, general=1,

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;

else if(noOfDays>=45 &&

noOfDays<=60){interestRate

=8;

else if(noOfDays>=61 &&

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\

n2.NRI");Scanners= new Scanner(System.in);

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;
}

public class Main{

publicstaticvoidmain(String[

]args){intt =4,choice;

doubleamount;

Scanners=newScanner(Syst

em.in);do{

System.out.println("SelectTheOption:\n1.InterestCalculator-SB\n2.InterestCalculator-
FD\n"

+ "3. Interest Calculator-RD\

n4. Exit\n");choice =s.nextInt();

switch(choice){

case 1: SBAccount ob1 = new

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;

case 2: FDAccount ob2 = new

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);

}
}

Screenshots Before Compiling The Code :


Screenshots After Compiling The Code :
Option -1
Enter the Average amount in your account : 10000
Interest gained : Rs. 400

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.

You might also like