0% found this document useful (0 votes)
19 views

Source Code

The document describes a Java program that calculates interest for different types of bank accounts (SB, FD, RD). It includes the algorithm, source code, and a flowchart. The algorithm has 6 steps that declare variables, get user input for the account type, and print the interest amount. The source code defines classes for each account type and calculates interest based on inputs. The flowchart shows the program flow, inputting the account type and printing outputs.

Uploaded by

Kaustubh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Source Code

The document describes a Java program that calculates interest for different types of bank accounts (SB, FD, RD). It includes the algorithm, source code, and a flowchart. The algorithm has 6 steps that declare variables, get user input for the account type, and print the interest amount. The source code defines classes for each account type and calculates interest based on inputs. The flowchart shows the program flow, inputting the account type and printing outputs.

Uploaded by

Kaustubh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Algorithm:-

STEP 1: Declare n

STEP 2: Initialize ch

STEP 3: Repeat while(ch==’l’) till step 5

STEP 4: Input n

STEP 5: switch(n)

if n==1, then Input avg, typeOfAccount and Print amount

if n==2, then Input avg, noOfDays, ageOfACHolder and Print amount

if n==3, then Input avg, noOfMonths, age and Print monthlyAmount

if n==4, then Print exit

STEP 6: STOP

___________________________________________________________________________________________
___________________________________________________________________________________________

Source Code:-

import java.util.Scanner;
abstract class Account{
double interestRate;
double amount;
abstract double calculateInterest();
}
class RDAccount extends Account{
double interestRate;
double amount;
int noOfMonths;
double monthlyAmount;
double calculateInterest() {
int age;
double i;
String type;
Scanner s2=new Scanner(System.in);
System.out.println("Enter the RD amount: ");
amount=s2.nextInt();
System.out.println("Enter the number of months: ");
noOfMonths=s2.nextInt();
System.out.println("Enter the age of account holder: ");
age=s2.nextInt();
if(age>60) {
type="SeniorCitizen";
}
else {
type="General";
}
if(type=="General") {
if(noOfMonths==6) {
interestRate=7.5;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==9) {
interestRate=7.75;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==12) {
interestRate=8;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==15) {
interestRate=8.25;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==18) {
interestRate=8.5;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==21) {
interestRate=8.75;
monthlyAmount=amount*interestRate/100;
}

}
else if(type=="SeniorCitizen") {
if(noOfMonths==6) {
interestRate=8;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==9) {
interestRate=8.25;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==12) {
interestRate=8.5;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==15) {
interestRate=8.75;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==18) {
interestRate=9;
monthlyAmount=amount*interestRate/100;
}
else if(noOfMonths==21) {
interestRate=9.25;
monthlyAmount=amount*interestRate/100;
}
}
System.out.println("Interest gained is: Rs. "+monthlyAmount);
return monthlyAmount;
}
}
class SBAccount extends Account{
double interestRate;
double amount;
String typeofaccount;
double calculateInterest() {
Scanner s=new Scanner(System.in);
int amt;
System.out.println("Enter the Average amount in your account: ");
amt=s.nextInt();
typeofaccount=s.nextLine();
if(typeofaccount=="Normal") {
interestRate=4;
amount=interestRate*amt/100;
}
else {
interestRate=6;
amount=interestRate*amt/100;
}
System.out.println("Interest Gained: Rs."+amount);
return amount;
}
}
class FDAccount extends Account{
double interestRate;
double amount;
int noOfDays;
int ageOfACHolder;
double calculateInterest() {
int amt;
String type;
Scanner s1=new Scanner(System.in);
System.out.println("Enter the FD amount:");
amt=s1.nextInt();
System.out.println("Enter the number of days: ");
noOfDays=s1.nextInt();
System.out.println("Enter your age: ");
ageOfACHolder=s1.nextInt();
if(ageOfACHolder>60) {
type="SeniorCitizen";
}
else {
type="General";
}
if(amt<10000000) {
if(type=="General") {
if(noOfDays>=7&&noOfDays<=14) {
interestRate=4.5;
amount=amt*interestRate/100;
}
else if(noOfDays>=15&&noOfDays<=29) {
interestRate=4.75;
amount=amt*interestRate/100;
}
else if(noOfDays>=30&&noOfDays<=45) {
interestRate=5.5;
amount=amt*interestRate/100;
}
else if(noOfDays>=45&&noOfDays<=60) {
interestRate=7;
amount=amt*interestRate/100;
}
else if(noOfDays>=61&&noOfDays<=184) {
interestRate=7.5;
amount=amt*interestRate/100;
}
else if(noOfDays>=185&&noOfDays<=366) {
interestRate=8;
amount=amt*interestRate/100;
}
}
else if(type=="SeniorCitizen") {
if(noOfDays>=7&&noOfDays<=14) {
interestRate=5;
amount=amt*interestRate/100;
}
else if(noOfDays>=15&&noOfDays<=29) {
interestRate=5.25;
amount=amt*interestRate/100;
}
else if(noOfDays>=30&&noOfDays<=45) {
interestRate=6;
amount=amt*interestRate/100;
}
else if(noOfDays>=45&&noOfDays<=60) {
interestRate=7.5;
amount=amt*interestRate/100;
}
else if(noOfDays>=61&&noOfDays<=184) {
interestRate=8;
amount=amt*interestRate/100;
}
else if(noOfDays>=185&&noOfDays<=366) {
interestRate=8.5;
amount=amt*interestRate/100;
}
}
}
else if(amt>10000000) {
if(noOfDays>=7&&noOfDays<=14) {
interestRate=6.5;
amount=amt*interestRate/100;
}
else if(noOfDays>=15&&noOfDays<=29) {
interestRate=6.75;
amount=amt*interestRate/100;
}
else if(noOfDays>=30&&noOfDays<=45) {
interestRate=6.75;
amount=amt*interestRate/100;
}
else if(noOfDays>=45&&noOfDays<=60) {
interestRate=8;
amount=amt*interestRate/100;
}
else if(noOfDays>=61&&noOfDays<=184) {
interestRate=8.5;
amount=amt*interestRate/100;
}
else if(noOfDays>=185&&noOfDays<=366) {
interestRate=10;
amount=amt*interestRate/100;
}

}
System.out.println("Interest gained is: Rs. "+amount);
return amount;
}
}
class interest {
public static void main(String[] args) {
int n;
char ch='l';
Scanner s=new Scanner(System.in);
while(ch=='l') {
System.out.println("\nMAIN MENU");
System.out.println("1. Interest Calculator - SB");
System.out.println("2. Interest Calculator - FD");
System.out.println("3. Interest Calculator - RD");
System.out.println("4. Exit");
System.out.println("Enter your option (1..4):");
n=s.nextInt();
switch(n) {
case 1:SBAccount obj=new SBAccount();
obj.calculateInterest();
break;
case 2:FDAccount obj1=new FDAccount();
obj1.calculateInterest();
break;
case 3:RDAccount obj2=new RDAccount();
obj2.calculateInterest();
break;
case 4:System.out.println("Thankyou for using app");
break;
}
}
s.close();
}
}

Output:-
Flowchart:-

START

Initialize n,ch

Input n

If n==1 Input avg, typeofAccount Print amount

If n==2 Input avg, noOfDays, ageofACHolder Print amount

If n==3 Input avg, noOfMonths,age Print monthlyAmount

If n==3 Print exit

STOP

You might also like