1.3 Aniket Java
1.3 Aniket Java
Experiment 1.3
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;
int time;
double calculateInterest() {
return (amount * interestRate * time) / 100;
}
}
double calculateInterest() {
return (amount * interestRate * time) / 100;
}
}
double calculateInterest() {
return (amount * interestRate * time) / 100;
}
}
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);
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;
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.