Stop 04 · Classes & ObjectsProjects · 1/1

Bank Account Management System

Part of the Java Roadmap

In short

This is the classic Java OOP project that interviewers love: a console banking app with savings and current accounts, deposits, withdrawals and transfers. Building it well shows you understand classes, encapsulation and static members together.

A console app with account classes (savings, current) that supports deposits, withdrawals, transfers and balance checks. It practises classes, constructors, encapsulation and static members.

The jaadu sits behind a wooden bank counter with a thick ledger book, sliding a neat stack of banknotes to a waiting customer.

Think of it like this

Running a small branch

Imagine you run a tiny cooperative bank branch in Indore. You open accounts, take deposits, refuse withdrawals that would overdraw, move money between customers and keep a ledger. Your program is that branch: each account is an object, and the bank class is the manager who keeps everything honest.

The big ideas

What you need to know

Encapsulation

balance is private and changes only through deposit and withdraw, so it can never go negative by accident.

static counter

One shared counter in the class guarantees unique account numbers.

Transfers

Withdraw from one account first. Only if that succeeds, deposit into the other.

Stretch goals

Minimum balance for savings, an overdraft limit for current accounts, and a transaction history list.

How it works

Building the bank

  1. 1

    Design the Account class

    Private accountNumber, holderName, balance and type. Validate in the constructor.

  2. 2

    Add behaviour

    deposit and withdraw check amounts and throw IllegalArgumentException for invalid ones.

  3. 3

    Number accounts

    A static counter generates unique account numbers like ACC1001.

  4. 4

    Create a Bank class

    Store accounts in a Map by number. Add open, find and transfer methods.

  5. 5

    Console menu

    A do-while loop with a switch expression for open, deposit, withdraw, transfer, balance and exit.

See it in code

Walk through the code

java
1import java.util.HashMap;2import java.util.Map;3 4class Account {5    private static int nextNumber = 1001;6 7    private final String number;8    private final String holder;9    private double balance;10 11    Account(String holder, double opening) {12        if (opening < 0) throw new IllegalArgumentException("Negative opening balance");13        this.number = "ACC" + nextNumber++;14        this.holder = holder;15        this.balance = opening;16    }17 18    void deposit(double amount) {19        if (amount <= 0) throw new IllegalArgumentException("Deposit must be positive");20        balance += amount;21    }22 23    void withdraw(double amount) {24        if (amount <= 0 || amount > balance) {25            throw new IllegalArgumentException("Invalid or insufficient amount");26        }27        balance -= amount;28    }29 30    String getNumber() { return number; }31    double getBalance() { return balance; }32    String getHolder() { return holder; }33}34 35public class Bank {36    private final Map<String, Account> accounts = new HashMap<>();37 38    Account open(String holder, double opening) {39        Account acc = new Account(holder, opening);40        accounts.put(acc.getNumber(), acc);41        return acc;42    }43 44    void transfer(String from, String to, double amount) {45        Account src = accounts.get(from);46        Account dst = accounts.get(to);47        if (src == null || dst == null) throw new IllegalArgumentException("Unknown account");48        src.withdraw(amount);49        dst.deposit(amount);50    }51 52    public static void main(String[] args) {53        Bank bank = new Bank();54        Account a = bank.open("Pooja", 10_000);55        Account b = bank.open("Vikram", 2_000);56        bank.transfer(a.getNumber(), b.getNumber(), 3_500);57        System.out.printf("%s %s: ₹%.2f%n", a.getNumber(), a.getHolder(), a.getBalance());58        System.out.printf("%s %s: ₹%.2f%n", b.getNumber(), b.getHolder(), b.getBalance());59    }60}

1/5A static counter gives ACC1001, ACC1002 and so on. nextNumber++ uses the value, then increments it.

The core of the project: a well-protected Account, a Bank that stores accounts by number, and a safe transfer.

Save yourself the pain

Common mistakes

Oops

Depositing into the target account before withdrawing from the source.

Do this instead

If the withdrawal then fails, the bank has created money. Always withdraw first.

Oops

Using a public balance field so the menu code can update it.

Do this instead

Keep it private. The menu should call deposit and withdraw, which enforce the rules.

Your mission

Finish the branch

~60 min

Quick check

Why should transfer() call withdraw on the source before deposit on the destination?

Go deeper

  1. 1Create an Account class with private fields and methods that validate every operation.
  2. 2Reject withdrawals above the balance and negative deposit amounts with clear messages.
  3. 3Push it to GitHub and keep extending it with inheritance, file saving and tests in later phases.

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge