0% found this document useful (0 votes)
7 views6 pages

Project1 - 1v - Simple Java Banking Application

The document describes a Simple Java Banking Application that allows users to create accounts, deposit, withdraw, and check balances using a console-based interface. It is structured using Object-Oriented Programming concepts and consists of three main classes: BankAccount, Bank, and BankingApp. The application provides a menu-driven interface for user interactions and includes instructions on how to compile and run the project.

Uploaded by

garvitmalik794
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Project1 - 1v - Simple Java Banking Application

The document describes a Simple Java Banking Application that allows users to create accounts, deposit, withdraw, and check balances using a console-based interface. It is structured using Object-Oriented Programming concepts and consists of three main classes: BankAccount, Bank, and BankingApp. The application provides a menu-driven interface for user interactions and includes instructions on how to compile and run the project.

Uploaded by

garvitmalik794
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Simple Java Banking Application

Simple Java Banking Application that includes features like


➢ account creation
➢ deposit
➢ withdrawal and
➢ balance inquiry
➢ The project is structured with OOP concepts (classes, objects,
encapsulation) and uses a console-based interface.

Project Structure:→
BankingApp/
│── BankingApp.java (Main class)
│── BankAccount.java (Bank account class)
│── Bank.java (Manages multiple accounts)

Step 1: BankAccount Class (Handles Individual Accounts)


// BankAccount.java
public class BankAccount {
private String accountNumber;
private String accountHolder;
private double balance;

// Constructor
public BankAccount(String accountNumber, String accountHolder,
double initialBalance) {
this.accountNumber = accountNumber;
this.accountHolder = accountHolder;
this.balance = initialBalance;
}

// Deposit method
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposit successful. New balance: $" +
balance);
} else {
System.out.println("Invalid deposit amount.");
}
}

// Withdraw method
public void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.println("Withdrawal successful. New balance: $" +
balance);
} else {
System.out.println("Insufficient funds or invalid amount.");
}
}

// Check balance
public double getBalance() {
return balance;
}

// Display account details


public void displayAccountInfo() {
System.out.println("\nAccount Holder: " + accountHolder);
System.out.println("Account Number: " + accountNumber);
System.out.println("Balance: $" + balance);
}

// Get account number (used in Bank class)


public String getAccountNumber() {
return accountNumber;
}
}

Step 2: Bank Class (Manages Multiple Accounts)


// Bank.java
import java.util.ArrayList;

public class Bank {


private ArrayList<BankAccount> accounts = new ArrayList<>();

// Create a new account


public void createAccount(String accountNumber, String
accountHolder, double initialBalance) {
BankAccount newAccount = new BankAccount(accountNumber,
accountHolder, initialBalance);
accounts.add(newAccount);
System.out.println("Account created successfully!");
}

// Find an account by account number


public BankAccount findAccount(String accountNumber) {
for (BankAccount account : accounts) {
if (account.getAccountNumber().equals(accountNumber)) {
return account;
}
}
return null;
}
}

Step 3: Main Application (User Interface)


// BankingApp.java
import java.util.Scanner;

public class BankingApp {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Bank bank = new Bank();

while (true) {
System.out.println("\n===== Banking System Menu =====");
System.out.println("1. Create Account");
System.out.println("2. Deposit Money");
System.out.println("3. Withdraw Money");
System.out.println("4. Check Balance");
System.out.println("5. Display Account Info");
System.out.println("6. Exit");
System.out.print("Choose an option: ");

int choice = scanner.nextInt();


scanner.nextLine(); // Consume newline
switch (choice) {
case 1: // Create account
System.out.print("Enter account number: ");
String accNum = scanner.nextLine();
System.out.print("Enter account holder name: ");
String accHolder = scanner.nextLine();
System.out.print("Enter initial deposit amount: ");
double initialBalance = scanner.nextDouble();
bank.createAccount(accNum, accHolder, initialBalance);
break;

case 2: // Deposit money


System.out.print("Enter account number: ");
accNum = scanner.nextLine();
BankAccount depositAccount = bank.findAccount(accNum);
if (depositAccount != null) {
System.out.print("Enter deposit amount: ");
double amount = scanner.nextDouble();
depositAccount.deposit(amount);
} else {
System.out.println("Account not found.");
}
break;

case 3: // Withdraw money


System.out.print("Enter account number: ");
accNum = scanner.nextLine();
BankAccount withdrawAccount = bank.findAccount(accNum);
if (withdrawAccount != null) {
System.out.print("Enter withdrawal amount: ");
double amount = scanner.nextDouble();
withdrawAccount.withdraw(amount);
} else {
System.out.println("Account not found.");
}
break;

case 4: // Check balance


System.out.print("Enter account number: ");
accNum = scanner.nextLine();
BankAccount balanceAccount = bank.findAccount(accNum);
if (balanceAccount != null) {
System.out.println("Current balance: $" +
balanceAccount.getBalance());
} else {
System.out.println("Account not found.");
}
break;

case 5: // Display account info


System.out.print("Enter account number: ");
accNum = scanner.nextLine();
BankAccount infoAccount = bank.findAccount(accNum);
if (infoAccount != null) {
infoAccount.displayAccountInfo();
} else {
System.out.println("Account not found.");
}
break;

case 6: // Exit
System.out.println("Thank you for using the banking system.");
scanner.close();
System.exit(0);

default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}

Features of This Banking App:→


✔ Create Account – Users can create a new account by entering an
account number, holder name, and initial deposit.
✔ Deposit Money – Users can deposit money into their account.
✔ Withdraw Money – Users can withdraw money while checking balance
constraints.
✔ Check Balance – Displays the current balance of an account.
✔ Display Account Info – Shows account details including account
number, holder's name, and balance.
✔ Uses OOP Concepts – Implements encapsulation and modular
programming.

How to Run the Project:→


1) Copy all three .java files (BankingApp.java, Bank.java,
BankAccount.java) into a folder.
2) Compile the code: javac *.java
3) Run the application: java BankingApp
4) Follow on-screen instructions to interact with the banking
system.

Sample Output:→
===== Banking System Menu =====
1. Create Account
2. Deposit Money
3. Withdraw Money
4. Check Balance
5. Display Account Info
6. Exit
Choose an option: 1

Enter account number: 12345


Enter account holder name: John Doe
Enter initial deposit amount: 5000
Account created successfully!

How System.exit(0) Works?


• System.exit(0): Terminates the program successfully.
• The number 0 indicates normal termination (no errors).
• If a non-zero value is used (e.g., System.exit(1);), it indicates an
abnormal termination due to an error.

You might also like