Project 2
All the banks operating in India are controlled by the RBI. RBI has set well-defined guidelines (e.g. minimum interest rate, minimum balance allowed, maximum withdrawal limit, etc) that all banks must follow. For example, suppose RBI has set the minimum interest rate applicable to a savings bank account to be 4% annually; however, banks are free to use a 4% interest rate or to set any rates above it.
Write a JAVA program to implement bank functionality in the above scenario and demonstrate the OOPs concepts and explain how it is actually satisfying that concept.
package ProjectTwoSkillLync;
import java.util.Scanner;
class Customer {
private String name;
private String typeOfAccount;
private String dateOfBirth;
private int accountNumber;
public Customer(String name, String typeOfAccount, String dateOfBirth, int accountNumber) {
this.name = name;
this.typeOfAccount = typeOfAccount;
this.dateOfBirth = dateOfBirth;
this.accountNumber = accountNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTypeOfAccount() {
return typeOfAccount;
}
public void setTypeOfAccount(String typeOfAccount) {
this.typeOfAccount = typeOfAccount;
}
public String getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(String dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
}
class Account {
private double balance;
public Account(double balance) {
this.balance = balance;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double calculateSimpleInterest(double rate, int years) {
double interest = (balance * rate * years) / 100;
return interest;
}
public double calculateCompoundInterest(double rate, int years, int compoundingFrequency) {
double compoundRate = 1 + (rate / compoundingFrequency);
double amount = balance * Math.pow(compoundRate, years * compoundingFrequency);
double interest = amount - balance;
return interest;
}
}
class RBI {
public double getInterestRate() {
return 0.0;
}
public double getWithdrawalLimit() {
return 0.0;
}
}
class SBI extends RBI {
@Override
public double getInterestRate() {
return 5.0;
}
@Override
public double getWithdrawalLimit() {
return 20000.0;
}
}
class ICICI extends RBI {
@Override
public double getInterestRate() {
return 4.5;
}
@Override
public double getWithdrawalLimit() {
return 25000.0;
}
}
public class BankManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Want to open an account? (yes/No)");
String answer = scanner.nextLine();
if (answer.equalsIgnoreCase("yes")) {
System.out.println("Insert name:");
String name = scanner.nextLine();
System.out.println("Type of account (Savings/Current):");
String typeOfAccount = scanner.nextLine();
System.out.println("Date of birth:");
String dateOfBirth = scanner.nextLine();
System.out.println("In which bank you want to open an account (SBI/ICICI):");
String bankName = scanner.nextLine();
RBI bank;
if (bankName.equalsIgnoreCase("SBI")) {
bank = new SBI();
} else if (bankName.equalsIgnoreCase("ICICI")) {
bank = new ICICI();
} else {
System.out.println("Invalid bank name.");
return;
}
int accountNumber = 123;
Customer customer = new Customer(name, typeOfAccount, dateOfBirth, accountNumber);
Account account = new Account(0.0);
System.out.println("Account has been opened and account number is: " + accountNumber);
System.out.println("Want to print mini statement? (yes/No)");
answer = scanner.nextLine();
if (answer.equalsIgnoreCase("yes")) {
System.out.println("Mini statement printed.");
}
System.out.println("Calculate interest? (yes/No)");
answer = scanner.nextLine();
if (answer.equalsIgnoreCase("yes")) {
System.out.println("How many years do you want to calculate the interest for?");
int years = scanner.nextInt();
scanner.nextLine();
double interestRate = bank.getInterestRate();
double interest;
if (typeOfAccount.equalsIgnoreCase("Savings")) {
interest = account.calculateSimpleInterest(interestRate, years);
} else if (typeOfAccount.equalsIgnoreCase("Current")) {
interest = account.calculateCompoundInterest(interestRate, years, 2);
} else {
System.out.println("Invalid account type.");
return;
}
System.out.println("Total interest: " + interest);
double totalAmount = account.getBalance() + interest;
System.out.println("Total amount: " + totalAmount);
}
} else {
System.out.println("No account opened.");
}
scanner.close();
}
}
Output Of the Program:
Want to open an account? (yes/No)
yes
Insert name:
Anthony
Type of account (Savings/Current):
Savings
Date of birth:
25/29/1998
In which bank you want to open an account (SBI/ICICI):
SBI
Account has been opened and account number is: 123
Want to print mini statement? (yes/No)
yes
Mini statement printed.
Calculate interest? (yes/No)
yes
How many years do you want to calculate the interest for?
2
Total interest: 0.0
Total amount: 0.0
yes
Insert name:
Anthony
Type of account (Savings/Current):
Savings
Date of birth:
25/29/1998
In which bank you want to open an account (SBI/ICICI):
SBI
Account has been opened and account number is: 123
Want to print mini statement? (yes/No)
yes
Mini statement printed.
Calculate interest? (yes/No)
yes
How many years do you want to calculate the interest for?
2
Total interest: 0.0
Total amount: 0.0