DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 1.3
Student Name: Aniket Kumar UID: 21BC1707
Branch: CSE Section/Group: 21BCS_CC-607(A)
Semester: 6th Date of Performance: 05/02/23
Subject Name: Project based learning with Java lab Subject Code: 21CSP-314
Aim: Create an application to calculate interest for FDs, RDs based on certain
conditions using inheritance.
Objective: Write a program to create an application to make an Account holders list and
calculate interest for FDs, RDs based on certain conditions using inheritance.
Code:
import java.util.ArrayList;
import java.util.Scanner;
abstract class Account {
double interestRate;
double amount;
int time;
abstract double calculateInterest();
}
class FDAccount extends Account {
FDAccount(double interestRate, double amount, int time) {
this.interestRate = interestRate;
this.amount = amount;
this.time = time ;
double calculateInterest() {
return (amount * interestRate * time) / 100;
}
}
class RDAccount extends Account {
RDAccount(double amount, double interestRate, int time) {
this.interestRate = interestRate;
this.amount = amount;
this.time = time ;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
double calculateInterest() {
return (amount * interestRate * time) / 100;
}
}
class SBAccount extends Account {
SBAccount(double interestRate, double amount, int time) {
this.interestRate = interestRate;
this.amount = amount;
this.time = time;
double calculateInterest() {
return (amount * interestRate * time) / 100;
}
}
public class CalInterest {
public static void main(String[] args) {
double amount;
int age;
int time;
int choice;
Scanner ip = new Scanner(System.in);
// choice = ip.nextInt();
ArrayList<Integer> fddays = new ArrayList<Integer>();
ArrayList<Double> General = new ArrayList<Double>();
ArrayList<Double> SeniorCitizen = new ArrayList<Double>();
ArrayList<Double> above = new ArrayList<Double>();
ArrayList<Integer> RDdays = new ArrayList<Integer>();
ArrayList<Double> General1 = new ArrayList<Double>();
ArrayList<Double> SeniorCitizen1 = new ArrayList<Double>();
fddays.add(8);
fddays.add(15);
fddays.add(16);
fddays.add(16);
fddays.add(124);
fddays.add(181);
General.add(4.50);
General.add(4.75);
General.add(5.50);
General.add(7.0);
General.add(7.50);
General.add(8.00);
SeniorCitizen.add(5.00);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
SeniorCitizen.add(5.25);
SeniorCitizen.add(6.00);
SeniorCitizen.add(7.50);
SeniorCitizen.add(8.00);
SeniorCitizen.add(8.50);
above.add(5.00);
above.add(5.25);
above.add(6.00);
above.add(7.50);
above.add(8.00);
above.add(8.50);
RDdays.add(8);
RDdays.add(15);
RDdays.add(16);
RDdays.add(16);
RDdays.add(124);
RDdays.add(181);
General1.add(7.50);
General1.add(7.75);
General1.add(8.00);
General1.add(8.25);
General1.add(8.50);
General1.add(8.75);
SeniorCitizen1.add(8.00);
SeniorCitizen1.add(8.25);
SeniorCitizen1.add(8.50);
SeniorCitizen1.add(8.75);
SeniorCitizen1.add(9.00);
SeniorCitizen1.add(9.25);
System.out.println("Choice 1 for SB");
System.out.println("Choice 2 for FD");
System.out.println("Choice 3 for RD");
choice = ip.nextInt();
switch (choice) {
case 2:
System.out.println("Enter the Amount");
amount = ip.nextInt();
if (amount > 10000000) {
System.out.println("Enter the days");
time = ip.nextInt();
if (fddays.contains(time)) {
int index = fddays.indexOf(time);
double interest = above.get(index);
FDAccount obj = new FDAccount(interest, amount, time);
double ans = obj.calculateInterest();
System.out.println(ans);
} else {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
System.out.println("Invalid days");
break;
}
} else {
System.out.println("Enter the age");
age = ip.nextInt();
if (age >= 60) {
System.out.println("Enter the time");
time = ip.nextInt();
if (fddays.contains(time)) {
int index = fddays.indexOf(time);
double interest = SeniorCitizen.get(index);
FDAccount obj = new FDAccount(interest, amount, time);
double ans = obj.calculateInterest();
System.out.println(ans);
} else {
System.out.println("Invalid days");
break;
}
} else {
System.out.println("Enter the time");
time = ip.nextInt();
if (fddays.contains(time)) {
int index = fddays.indexOf(time);
double interest = General.get(index);
FDAccount obj = new FDAccount(interest, amount, time);
double ans = obj.calculateInterest();
System.out.println("ans");
} else {
System.out.println("Invalid days");
break;
}
}
break;
case 1:
int nri = 0;
int normal = 1;
int choice2;
System.out.println("Choose whether a person is normal person or nri");
choice2 = ip.nextInt();
switch (choice2) {
case 0:
System.out.println("Enter the days");
time = ip.nextInt();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
System.out.println("Enter the amount");
amount = ip.nextInt();
SBAccount obj = new SBAccount(6, amount, time);
double ans = obj.calculateInterest();
System.out.println(ans);
break;
case 1:
System.out.println("Enter the days");
time = ip.nextInt();
System.out.println("Enter the amount");
amount = ip.nextInt();
SBAccount obj1 = new SBAccount(4, amount, time);
double ans1 = obj1.calculateInterest();
System.out.println(ans1);
break;
}
break;
case 3:
System.out.println("Enter the Amount");
amount = ip.nextInt();
System.out.println("Enter the Amount");
System.out.println("Enter the age");
age = ip.nextInt();
if (age >= 60) {
System.out.println("Enter the time");
time = ip.nextInt();
if (fddays.contains(time)) {
int index = fddays.indexOf(time);
double interest = SeniorCitizen.get(index);
FDAccount obj = new FDAccount(interest, amount, time);
double ans = obj.calculateInterest();
System.out.println(ans);
} else {
System.out.println("Invalid days");
break;
}
} else {
System.out.println("Enter the time");
time = ip.nextInt();
if (fddays.contains(time)) {
int index = fddays.indexOf(time);
double interest = General.get(index);
FDAccount obj = new FDAccount(interest, amount, time);
double ans = obj.calculateInterest();
System.out.println(ans);
} else {
System.out.println("Invalid days");
break;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output
Learning Outcomes:
• Learnt about inheritance and found that it is the method to create a hierarchy between classes by inheriting
from other classes
• Learnt about classes and how they work.
• Learnt about loops that it is a feature used to execute a particular part of the program repeatedly if a given
condition evaluates to be true
• Learnt about how to use conditional statements.