A console-based banking system built using Object-Oriented Programming (OOP) principles in Java.
This project simulates basic banking operations such as creating accounts, depositing money, withdrawing money, viewing balance, and viewing transaction history β with proper exception handling and clean separation of concerns.
- Create a new bank account
- Deposit money
- Withdraw money (with rules)
- View account balance
- View transaction history
- Robust exception handling
- Uses cents instead of floating-point values for money accuracy
-
Encapsulation
- Account data (balance, account number) is private and accessed via methods.
-
Abstraction
- Business rules are handled by the service layer.
-
Separation of Concerns
modelβ domain objectsserviceβ business logicMainβ user interaction
-
Exception Handling
- Custom and built-in runtime exceptions are used for rule violations.
com.bank com.bank βββ Main.java
βββ exception
β βββ AccountNotFoundException.java
β βββ InsufficientBalanceException.java
β βββ InvalidAmountException.java
βββ model
β βββ Account.java
β βββ Transaction.java
βββ service
| βββ BankService.java
- Deposit amount must be positive
- Withdraw amount must be:
- Positive
- Less than the maximum withdraw limit
- Leave at least minimum balance in the account
- Account must exist for any operation
Violations of these rules throw runtime exceptions.
-
Service Layer
- Throws exceptions when rules are violated
- Does not print messages
-
Main Class
- Catches exceptions
- Displays user-friendly messages
try {
service.deposit(accNo, amount);
System.out.println("Deposit successful!");
} catch (RuntimeException e) {
System.out.println(e.getMessage());
}