Java exp3 js
Java exp3 js
Experiment 3
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;
this.accountHolderName = accountHolderName;
this.principal = principal;
this.rateOfInterest = rateOfInterest;}
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int tenureInYears;
tenureInYears) {
this.tenureInYears = tenureInYears;
super.displayDetails();
int months;
double monthlyDeposit;
int months) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
super(accountHolderName, 0, rateOfInterest);
this.monthlyDeposit = monthlyDeposit;
this.months = months;
double n = months;
// Example FD account
fd.displayDetails();
System.out.println();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
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.