Banking System Lab 2

Due Date

Overview

This project follows Object-Oriented Programming (OOP) principles to create a banking system with different account types and notification methods.

Implementation Steps

  • Create a Java Project

    Set up a Java project in your preferred IDE (e.g., IntelliJ IDEA).

  • Define the Notification Interface (OCP)

    Create an interface Notification to send messages.

    interface Notification {
        void send(String message);
    }
  • Implement Notification Types

    Create three classes implementing Notification:

    • EmailNotification
    • SMSNotification
    • WhatsAppNotification

    Each should override send() to print messages.

    class EmailNotification implements Notification {
        @Override
        public void send(String message) {
            System.out.println("[Email] " + message);
        }
    }
  • Define Banking Interfaces (ISP)

    Create three interfaces for account functionalities:

    • DepositAccount → for deposits
    • WithdrawableAccount → for withdrawals
    • BalanceCheck → to check balance
    interface DepositAccount {
        void deposit(double amount);
    }
  • Implement Savings Account (LSP)

    Create a SavingsAccount class implementing deposit, withdraw, and balance check.

    class SavingsAccount implements DepositAccount, WithdrawableAccount, BalanceCheck {
        private double balance;
        private Notification notification;
    
        public SavingsAccount(double initialBalance, Notification notification) {
           
        }
    
        @Override
        public void deposit(double amount) {
            balance += amount;
            notification.send("Deposited $" + amount + ". New Balance: $" + balance);
        }
    }
  • Implement Loan and Crypto Accounts

    Create:

    • LoanAccount → Can only accept deposits (loan repayments).
    • CryptoAccount → Can only accept deposits (crypto investments).

    Each should notify when a deposit is made.

  • Create the Main Class

    In Main.java, test all accounts:

    public class Main {
        public static void main(String[] args) {
            SavingsAccount savings = new SavingsAccount(1000, new EmailNotification());
            savings.deposit(500);
        }
    }
  • Expected Output

                        
                        === Banking Transactions ===
                        [Email Notification] Deposited $500. New Balance: $1500
                        [Email Notification] Withdrew $200. New Balance: $1300
                        [Email Notification] Withdrawal failed due to insufficient funds!
                        
                        === Loan Repayment ===
                        [SMS Notification] Loan repayment of $1000. Remaining Loan: $4000
                        Loan Balance: $4000
                        
                        === Crypto Account ===
                        [WhatsApp Notification] Crypto deposited $700. New Balance: $700
                        Crypto Balance: $700