This project follows Object-Oriented Programming (OOP) principles to create a banking system with different account types and notification methods.
Set up a Java project in your preferred IDE (e.g., IntelliJ IDEA).
Create an interface Notification to send messages.
interface Notification {
void send(String message);
}
Create three classes implementing Notification:
EmailNotificationSMSNotificationWhatsAppNotificationEach should override send() to print messages.
class EmailNotification implements Notification {
@Override
public void send(String message) {
System.out.println("[Email] " + message);
}
}
Create three interfaces for account functionalities:
DepositAccount → for depositsWithdrawableAccount → for withdrawalsBalanceCheck → to check balance
interface DepositAccount {
void deposit(double amount);
}
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);
}
}
Create:
LoanAccount → Can only accept deposits (loan repayments).CryptoAccount → Can only accept deposits (crypto investments).Each should notify when a deposit is made.
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);
}
}
=== 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