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

Java exp3 js

The document outlines an experiment for a Computer Science and Engineering course where students create a Java application to calculate interest for Fixed Deposits (FDs) and Recurring Deposits (RDs) using inheritance. It includes the aim, objectives, algorithm, and code for the application, demonstrating object-oriented programming principles such as inheritance, method overriding, and encapsulation. The learning outcomes emphasize the understanding of class interactions and interest calculation methodologies.

Uploaded by

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

Java exp3 js

The document outlines an experiment for a Computer Science and Engineering course where students create a Java application to calculate interest for Fixed Deposits (FDs) and Recurring Deposits (RDs) using inheritance. It includes the aim, objectives, algorithm, and code for the application, demonstrating object-oriented programming principles such as inheritance, method overriding, and encapsulation. The learning outcomes emphasize the understanding of class interactions and interest calculation methodologies.

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 3

Student Name: Jashanpreet Singh UID: 22BCS11724


Branch: CSE Section/Group:635/B
Semester: 6th DOP:
Subject: PBLJ Lab Subject Code: 22CSH-359

Aim: Create an application to calculate interest for FDs, RDs based on certain conditions using inheritance.

Objective: To develop a Java application that calculates interest for Fixed Deposits (FDs)
and Recurring Deposits (RDs) using object-oriented programming principles. The application
will use inheritance to define common properties and methods for accounts while providing
specific implementations for FDs and RDs based on their respective conditions.

Algorithm:
 Create Account class with attributes: accountHolderName, principal, rateOfInterest. Include
methods for calculating interest (to be overridden) and displaying details.
 Create FixedDeposit subclass that calculates FD interest using: principal * rateOfInterest *
tenureInYears / 100. Display FD details.
 Create RecurringDeposit subclass that calculates RD interest using: (monthlyDeposit * months *
(months + 1) / 2) * (rateOfInterest / (12 * 100)). Display RD details.
 In main method, create instances of FixedDeposit and RecurringDeposit and display their details.

Code:
class Account {

String accountHolderName;

double principal;

double rateOfInterest;

public Account(String accountHolderName, double principal, double rateOfInterest) {

this.accountHolderName = accountHolderName;

this.principal = principal;

this.rateOfInterest = rateOfInterest;}

public double calculateInterest() {

return 0;

}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public void displayDetails() {

System.out.println("Account Holder: " + accountHolderName);

System.out.println("Principal Amount: " + principal);

System.out.println("Rate of Interest: " + rateOfInterest + "%");

class FixedDeposit extends Account {

int tenureInYears;

public FixedDeposit(String accountHolderName, double principal, double rateOfInterest, int

tenureInYears) {

super(accountHolderName, principal, rateOfInterest);

this.tenureInYears = tenureInYears;

public double calculateInterest() {

return principal * rateOfInterest * tenureInYears / 100;

public void displayDetails() {

super.displayDetails();

System.out.println("Tenure (Years): " + tenureInYears);

System.out.println("Interest Amount: " + calculateInterest());}}

class RecurringDeposit extends Account {

int months;

double monthlyDeposit;

public RecurringDeposit(String accountHolderName, double monthlyDeposit, double rateOfInterest,

int months) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

super(accountHolderName, 0, rateOfInterest);

this.monthlyDeposit = monthlyDeposit;

this.months = months;

public double calculateInterest() {

// RD interest formula: P(n(n+1)/2) * (r / 12 * 100)

double n = months;

return (monthlyDeposit * n * (n + 1) / 2) * (rateOfInterest / (12 * 100));

public void displayDetails() {

System.out.println("Account Holder: " + accountHolderName);

System.out.println("Monthly Deposit: " + monthlyDeposit);

System.out.println("Number of Months: " + months);

System.out.println("Rate of Interest: " + rateOfInterest + "%");

System.out.println("Interest Amount: " + calculateInterest());

public class InterestCalculator {

public static void main(String[] args) {

// Example FD account

FixedDeposit fd = new FixedDeposit("Sakshi", 100000, 5.5, 3);

System.out.println("Fixed Deposit Details:");

fd.displayDetails();

System.out.println();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

RecurringDeposit rd = new RecurringDeposit("Sakshi_22BCS11571", 5000, 6.5, 12);

System.out.println("Recurring Deposit Details:");

rd.displayDetails();

Output:

Learning Outcomes:

 Inheritance: Use of base and derived classes for shared attributes and methods.
 Method Overriding: Custom implementation of methods in subclasses.
 Constructor: Initializing object attributes using constructors.
 Encapsulation: Storing and manipulating data within objects.
 Polymorphism: Different behavior of calculateInterest() based on object type.
 Interest Calculation: Implementing FD and RD interest formulas.
 Class Interaction: Creating objects and calling methods to display details.

You might also like