A Simple Banking System Simulation is an excellent Java project for beginners eager to practice classes, objects, user input, variables, methods, menu-driven programs, and state management. This project simulates banking basics like balance checks, deposits, and withdrawals—all through the console.
What Will This Banking System Do?
- Allow users to check their account balance.
- Make deposits and withdrawals.
- Display account information.
- Exit via a menu.
- All data is stored in-memory—no external files or databases.
Concepts Practiced in This Project
- Classes & Objects: Representing a bank account with fields and methods.
- User Input: Using Scanner for seamless interaction.
- Conditional Logic: Ensuring valid transactions (can’t withdraw more than the balance).
- Menu-Driven Programs: Using loops and switch-case to navigate options.
- Encapsulation: Using getters/setters for data protection.
Step 1: The BankAccount
Class
First, define a class to represent accounts:
java
public class BankAccount {
private String ownerName;
private String accountNumber;
private double balance;
// Constructor
public BankAccount(String ownerName, String accountNumber, double initialBalance) {
this.ownerName = ownerName;
this.accountNumber = accountNumber;
this.balance = initialBalance;
}
// Deposit money
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposit successful!");
} else {
System.out.println("Amount must be positive.");
}
}
// Withdraw money
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.println("Withdrawal successful!");
} else if (amount > balance) {
System.out.println("Insufficient funds.");
} else {
System.out.println("Amount must be positive.");
}
}
// Check balance
public double getBalance() {
return balance;
}
// Show account info
public void displayInfo() {
System.out.println("Account Holder: " + ownerName);
System.out.println("Account Number: " + accountNumber);
System.out.printf("Balance: %.2f\n", balance);
}
}
Explanation:
- Fields hold the owner's name, account number, and balance.
- Methods handle deposits, withdrawals (with validation), balance checks, and displaying info.
- Encapsulation keeps sensitive data (private fields).
- Feedback messages tell users if actions succeed or fail.
Step 2: The Main Program with Menu
Now, create the interface for users to interact with their account:
java
import java.util.Scanner;
public class BankingSystem {
public static void main(String[] args) {
// Set up account for demonstration
BankAccount account = new BankAccount("John Doe", "123456789", 1000.0);
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("\n--- Simple Banking System Menu ---");
System.out.println("1. Check Balance");
System.out.println("2. Deposit Money");
System.out.println("3. Withdraw Money");
System.out.println("4. Display Account Information");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.printf("Current Balance: %.2f\n", account.getBalance());
break;
case 2:
System.out.print("Enter deposit amount: ");
double depositAmount = scanner.nextDouble();
account.deposit(depositAmount);
break;
case 3:
System.out.print("Enter withdrawal amount: ");
double withdrawAmount = scanner.nextDouble();
account.withdraw(withdrawAmount);
break;
case 4:
account.displayInfo();
break;
case 5:
System.out.println("Thank you for using our banking system. Goodbye!");
break;
default:
System.out.println("Invalid choice! Please select 1-5.");
}
} while (choice != 5);
scanner.close();
}
}
How it Works: Key Parts Explained
- The main menu offers five options—each triggering the appropriate BankAccount method.
- Deposit and withdraw amounts must be positive; withdrawals also check for sufficient balance.
- All feedback is immediate, ensuring the user knows the result of each action.
- Information is displayed in a clean, readable format.
How to Run This Project
1.Create two files in the same folder:
BankAccount.java
BankingSystem.java
2.Compile both:
text
javac BankAccount.java BankingSystem.java
3.Run the program:
text
java BankingSystem
Follow menu prompts to interact with your simulated bank account.
Possible Expansions
- Allow multiple accounts (store a list of
BankAccount
objects). - Implement user authentication (username/password).
- Add money transfers between accounts.
- Persist data to a file (basic
I/O
). - Add an overdraft limit or account types (savings/current, etc.).
Why This Project is Perfect for Beginners
- Teaches OOP design: Use of classes, objects, constructors, and encapsulation.
- Real-world logic: Mimics familiar banking operations—deposits, withdrawals, info display. -** Menu navigation:** Menu-driven approach is the backbone of many CLI applications.
- Input validation: Controls how and what users can do, building robust logic.
By building this Simple Banking System Simulation, you’ll combine multiple foundational Java skills into a usable, extendable mini-app—perfect for portfolios, practice, and jumping to even bigger projects!
Check out the YouTube Playlist for great java developer content for basic to advanced topics.
Please Do Subscribe Our YouTube Channel for clearing programming concept and much more ... : CodenCloud
Top comments (0)