0% found this document useful (0 votes)
14 views7 pages

Bank Management Complete

The document presents a Java implementation of a Bank Management System using Object-Oriented Programming concepts. It defines an abstract class 'BankAccount' and two subclasses 'SavingsAccount' and 'CurrentAccount', each with methods for depositing, withdrawing, and displaying balance. The program allows users to interact with their accounts through a console interface, demonstrating encapsulation, abstraction, inheritance, and polymorphism.

Uploaded by

snehitha4dammai
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)
14 views7 pages

Bank Management Complete

The document presents a Java implementation of a Bank Management System using Object-Oriented Programming concepts. It defines an abstract class 'BankAccount' and two subclasses 'SavingsAccount' and 'CurrentAccount', each with methods for depositing, withdrawing, and displaying balance. The program allows users to interact with their accounts through a console interface, demonstrating encapsulation, abstraction, inheritance, and polymorphism.

Uploaded by

snehitha4dammai
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/ 7

Bank Management System Using OOP Concepts

Java Code:

import java.util.Scanner;

abstract class BankAccount {

protected String accountHolderName;

protected String accountNumber;

protected double balance;

public BankAccount(String accountHolderName, String accountNumber, double balance) {

this.accountHolderName = accountHolderName;

this.accountNumber = accountNumber;

this.balance = balance;

public abstract void deposit(double amount);

public abstract void withdraw(double amount);

public void displayBalance() {

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

System.out.println("Account Number: " + accountNumber);

System.out.println("Balance: $" + balance);

}
class SavingsAccount extends BankAccount {

private double interestRate;

public SavingsAccount(String accountHolderName, String accountNumber, double

balance, double interestRate) {

super(accountHolderName, accountNumber, balance);

this.interestRate = interestRate;

@Override

public void deposit(double amount) {

if (amount > 0) {

balance += amount;

System.out.println("Deposited: $" + amount);

} else {

System.out.println("Invalid deposit amount.");

@Override

public void withdraw(double amount) {

if (amount > 0 && amount <= balance) {

balance -= amount;

System.out.println("Withdrawn: $" + amount);

} else {

System.out.println("Invalid withdrawal amount or insufficient balance.");


}

public void addInterest() {

double interest = balance * (interestRate / 100);

balance += interest;

System.out.println("Interest added: $" + interest);

class CurrentAccount extends BankAccount {

private double overdraftLimit;

public CurrentAccount(String accountHolderName, String accountNumber, double

balance, double overdraftLimit) {

super(accountHolderName, accountNumber, balance);

this.overdraftLimit = overdraftLimit;

@Override

public void deposit(double amount) {

if (amount > 0) {

balance += amount;

System.out.println("Deposited: $" + amount);

} else {

System.out.println("Invalid deposit amount.");

}
}

@Override

public void withdraw(double amount) {

if (amount > 0 && (balance - amount >= -overdraftLimit)) {

balance -= amount;

System.out.println("Withdrawn: $" + amount);

} else {

System.out.println("Withdrawal exceeds overdraft limit or invalid amount.");

public class BankManagementSystem {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

SavingsAccount savingsAccount = new SavingsAccount("John Doe", "SA12345", 1000,

5);

CurrentAccount currentAccount = new CurrentAccount("Jane Smith", "CA12345",

2000, 500);

System.out.println("Choose an account type:");

System.out.println("1. Savings Account");

System.out.println("2. Current Account");

int choice = scanner.nextInt();

BankAccount account = (choice == 1) ? savingsAccount : currentAccount;


while (true) {

System.out.println("\nChoose an action:");

System.out.println("1. Deposit");

System.out.println("2. Withdraw");

System.out.println("3. Check Balance");

if (account instanceof SavingsAccount) System.out.println("4. Add

Interest");

System.out.println("5. Exit");

int action = scanner.nextInt();

switch (action) {

case 1 -> account.deposit(scanner.nextDouble());

case 2 -> account.withdraw(scanner.nextDouble());

case 3 -> account.displayBalance();

case 4 -> {

if (account instanceof SavingsAccount) ((SavingsAccount)

account).addInterest();

case 5 -> System.exit(0);

Example Output:
Input:

Choose an account type:

1. Savings Account

2. Current Account

Choose an action:

1. Deposit

2. Withdraw

3. Check Balance

4. Add Interest

5. Exit

Enter amount to deposit: 500

Output:

Deposited: $500

Explanation:

1. Encapsulation: Protects data like accountHolderName and balance, accessed through methods.

2. Abstraction: BankAccount is an abstract class, providing a blueprint for derived classes.

3. Inheritance: SavingsAccount and CurrentAccount inherit common features from BankAccount.

4. Polymorphism: BankAccount reference is used for both SavingsAccount and CurrentAccount.


The program demonstrates a simple bank system with deposit, withdraw, and interest operations.

You might also like