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());
}