Java Exp 1.2
Java Exp 1.2
Aim: Create an application to calculate interest for FDs, RDs based on certain conditions using
inheritance.
Objective Create an application to calculate interest for Fixed Deposits (FDs) and
Recurring Deposits (RDs) using inheritance. The system will ensure accurate calculations
based on specific conditions, support modularity for future enhancements, and maintain a
user-friendly interface for seamless operation.
Algorithm:
Define Classes:
Menu-Driven Operations:
@Override
public double calculateInterest() {
return (amount * rate) / 100;
}
}
@Override
public double calculateInterest() {
return (amount * rate) / 100;
}
}
@Override
public double calculateInterest() {
return (amount * (months + 1) / 2) * (rate / 100) * (1.0 / 12);
}
}
while (true) {
System.out.println("... Bank Management System......\n");
System.out.println("...code by Prince Kumar...\n");
System.out.println("1. SB Interest\n2. FD Interest\n3. RD Interest\n4. Exit");
int option = sc.nextInt();
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
try {
if (option == 1) {
System.out.println("Enter amount:");
double amt = sc.nextDouble();
System.out.println("Type (Normal/NRI):");
sc.nextLine();
String type = sc.nextLine();
SBAccount sb = new SBAccount(amt, type);
System.out.println("Interest: Rs. " + sb.calculateInterest());
} else if (option == 2) {
System.out.println("Enter amount:");
double amt = sc.nextDouble();
System.out.println("Days:");
int days = sc.nextInt();
System.out.println("Age:");
int age = sc.nextInt();
FDAccount fd = new FDAccount(amt, days, age);
System.out.println("Interest: Rs. " + fd.calculateInterest());
} else if (option == 3) {
System.out.println("Monthly deposit:");
double deposit = sc.nextDouble();
System.out.println("Months:");
int months = sc.nextInt();
System.out.println("Age:");
int age = sc.nextInt();
RDAccount rd = new RDAccount(deposit, months, age);
System.out.println("Interest: Rs. " + rd.calculateInterest());
} else if (option == 4) {
System.out.println("Exiting...");
break;
} else {
System.out.println("Invalid option!");
}
} catch (InvalidInput e) {
System.out.println(e.getMessage());
}
}
sc.close();
}
}
Output:
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
Learning Outcomes:
Understand how to create and use classes to represent real-world entities and implement inheritance
in object-oriented programming.
Develop skills in using loops, conditionals, and methods to manage program flow and perform specific tasks like
interest calculations
Learn to handle dynamic data efficiently by integrating data structures like ArrayList for managing
multiple objects.
Design user-friendly systems with menu-driven interfaces and robust error handling through custom
exceptions.