Skip to main content
Course/Module 10/Topic 1 of 3Advanced

Project Architecture & Account Class

In this capstone project, you'll build a complete Banking Application that ties together everything you've learned: OOP, collections, exception handling, and file I/O. We start by designing the account system with proper encapsulation.

45 minBy Priygop TeamLast updated: Feb 2026

Project Overview

  • Build a fully functional console-based Banking Application
  • Uses OOP (classes, inheritance, encapsulation, polymorphism)
  • Uses Collections (ArrayList, HashMap) for data storage
  • Uses Exception Handling for robust error management
  • Features: Create accounts, deposit, withdraw, transfer, view transaction history

Account Class Design

Example
import java.util.*;

class Transaction {
    String type;
    double amount;
    String description;
    String date;
    
    Transaction(String type, double amount, String description) {
        this.type = type;
        this.amount = amount;
        this.description = description;
        this.date = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
            .format(new Date());
    }
    
    @Override
    public String toString() {
        return String.format("[%s] %-10s $%,.2f - %s", date, type, amount, description);
    }
}

class BankAccount {
    private String accountNumber;
    private String ownerName;
    private double balance;
    private String accountType;
    private ArrayList<Transaction> transactions;
    
    BankAccount(String ownerName, String accountType, double initialDeposit) {
        this.accountNumber = "ACC-" + String.format("%04d", (int)(Math.random() * 10000));
        this.ownerName = ownerName;
        this.accountType = accountType;
        this.balance = initialDeposit;
        this.transactions = new ArrayList<>();
        
        if (initialDeposit > 0) {
            transactions.add(new Transaction("DEPOSIT", initialDeposit, "Initial deposit"));
        }
    }
    
    // Getters
    String getAccountNumber() { return accountNumber; }
    String getOwnerName() { return ownerName; }
    double getBalance() { return balance; }
    String getAccountType() { return accountType; }
    
    // Deposit with validation
    void deposit(double amount) throws IllegalArgumentException {
        if (amount <= 0) throw new IllegalArgumentException("Deposit must be positive");
        balance += amount;
        transactions.add(new Transaction("DEPOSIT", amount, "Cash deposit"));
        System.out.println("Deposited $" + String.format("%.2f", amount));
    }
    
    // Withdraw with validation
    void withdraw(double amount) throws IllegalArgumentException {
        if (amount <= 0) throw new IllegalArgumentException("Amount must be positive");
        if (amount > balance) throw new IllegalArgumentException("Insufficient funds");
        balance -= amount;
        transactions.add(new Transaction("WITHDRAW", amount, "Cash withdrawal"));
        System.out.println("Withdrew $" + String.format("%.2f", amount));
    }
    
    // Print account info
    void printInfo() {
        System.out.println("\n=== Account Info ===");
        System.out.println("Account: " + accountNumber);
        System.out.println("Owner: " + ownerName);
        System.out.println("Type: " + accountType);
        System.out.println("Balance: $" + String.format("%,.2f", balance));
    }
    
    // Print transaction history
    void printTransactions() {
        System.out.println("\n=== Transaction History: " + accountNumber + " ===");
        if (transactions.isEmpty()) {
            System.out.println("No transactions yet.");
        } else {
            for (Transaction t : transactions) {
                System.out.println(t);
            }
        }
    }
}

public class BankingApp {
    public static void main(String[] args) {
        // Create an account
        BankAccount account = new BankAccount("Alice Johnson", "Savings", 1000);
        account.printInfo();
        
        // Perform transactions
        try {
            account.deposit(500);
            account.withdraw(200);
            account.deposit(1000);
            account.withdraw(300);
        } catch (IllegalArgumentException e) {
            System.out.println("Error: " + e.getMessage());
        }
        
        // View results
        account.printInfo();
        account.printTransactions();
    }
}

Try It Yourself: Build Your Account

Try It Yourself: Build Your AccountJava
Java Editor
✓ ValidTab = 2 spaces
Java|54 lines|1549 chars|✓ Valid syntax
UTF-8

Quick Quiz: Project Architecture

Chat on WhatsApp
Priygop - Leading Professional Development Platform | Expert Courses & Interview Prep