0% found this document useful (0 votes)
9 views6 pages

Exp 3

The document outlines an experiment for calculating interest based on account types and holder status in Java. It includes objectives for creating separate classes for different account types derived from an abstract class, along with an implementation code for calculating interest for savings, fixed, and recurring deposit accounts. Additionally, it highlights learning outcomes related to class design, method implementation, and program structure.
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)
9 views6 pages

Exp 3

The document outlines an experiment for calculating interest based on account types and holder status in Java. It includes objectives for creating separate classes for different account types derived from an abstract class, along with an implementation code for calculating interest for savings, fixed, and recurring deposit accounts. Additionally, it highlights learning outcomes related to class design, method implementation, and program structure.
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/ 6

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 3
Student Name: Aakanksha Sharma UID:22BCS16783
Branch: BE-CSE Section/Group: IOT-632/A
Semester:6th Date of Performance:27-01-25
Subject Name: Project Based Learning Subject Code: 22CSH-359
in Java with Lab

1. Aim: Calculate interest based on the type of the account and the status of the account
holder. The rates of interest changes according to the amount (greater than or less than
1 crore), age of account holder (General or Senior citizen) and number of days if the
type of account is FD or RD
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2. Objective: Separate classes should be created for the different types of accounts. All
classes should be derives from an abstract class named ‘Account’ which contains a
method called ‘calculateInterest’. Implement the calculateInterest method according to the
type of the account, interest rates, amount and age of the account holder. 4If the user is
entering any invalid value (For eg. Negative value) in any fields, raise a user defined
exception.

3. Implementation/Code:

import java.util.Scanner;

class SBAccount {
private double balance;

public SBAccount(double balance) {


this.balance = balance;
}

public double calculateInterest() {


double rate = 4.0; // Assume 4% interest for SB account
return (balance * rate) / 100;
}
}

class FDAccount {
private double principal; private
int tenure;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public FDAccount(double principal, int tenure) { this.principal


= principal;
this.tenure = tenure;
}

public double calculateInterest() {


double rate = 6.5; // Assume 6.5% interest for FD account
return (principal * rate * tenure) / 100;
}
}

class RDAccount {
private double monthlyDeposit; private
int tenure;

public RDAccount(double monthlyDeposit, int tenure) {


this.monthlyDeposit = monthlyDeposit;
this.tenure = tenure;
}

public double calculateInterest() {


double rate = 7.0; // Assume 7% interest for RD account
return (monthlyDeposit * tenure * (tenure + 1) / 2 * rate) / 100;
}
}
public class InterestCalculator {
public static void main(String[] args) { Scanner
scanner = new Scanner(System.in);

System.out.print("Enter your name: "); String


name = scanner.nextLine();

int option;
do {
System.out.println("\nSelect the option:");
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.print("Enter
your choice: ");
option = scanner.nextInt();

switch (option) {
case 1: // SB Account
System.out.print("Enter balance in your SB Account: ");
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
double sbBalance = scanner.nextDouble(); SBAccount
sbAccount = new SBAccount(sbBalance);
System.out.printf("\n*********************\n");
System.out.printf(" Hello, %s! \n", name);
System.out.printf(" Interest Gained (SB): ₹ %.2f \n",
sbAccount.calculateInterest());
System.out.printf("*********************\n");
break;

case 2 : // FD Account
System.out.print("Enter principal amount for FD: "); double
principal = scanner.nextDouble(); System.out.print("Enter
tenure (in years): ");
int fdTenure = scanner.nextInt();
FDAccount fdAccount = new FDAccount(principal, fdTenure);
System.out.printf("\n*********************\n");
System.out.printf(" Hello, %s! \n", name); System.out.printf("
Interest Gained (FD): ₹ %.2f \n",
fdAccount.calculateInterest());
System.out.printf("*********************\n");
break;

case 3: // RD Account
System.out.print("Enter monthly deposit for RD: "); double
monthlyDeposit = scanner.nextDouble();
System.out.print("Enter tenure (in months): ");
int rdTenure = scanner.nextInt();
RDAccount rdAccount = new RDAccount(monthlyDeposit, rdTenure);
System.out.printf("\n*********************\n"); System.out.printf("
Hello, %s! \n", name);
System.out.printf(" Interest Gained (RD): ₹ %.2f \n",
rdAccount.calculateInterest());
System.out.printf("*********************\n");
break;

case 4: // Exit
System.out.println("\nThank you for using the Interest Calculator. Goodbye!");
break;

default:
System.out.println("\nInvalid choice. Please try again.");
}
} while (option != 4);

scanner.close();
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4.Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5. Learning Outcomes:
• Designed a functional system to manage video rentals, demonstrating the use of
classes and objects in Java.
• Implemented methods for operations like adding videos, renting out, returning, and
recording user ratings.
• Applied arrays to store and efficiently manage the video inventory within the store.
• Learnt to integrate multiple classes and enable seamless interaction among them in
a structured program.

You might also like