Simple Banking Application Using CORE
Simple Banking Application Using CORE
# Task Description
Create a simple banking system program in Java. The program should perform the
following operations:
2. Deposit money.
3. Withdraw money.
# Task Steps
1. **Define the BankAccount Class:**
- `String accountNumber`
- `String accountHolderName`
- `double balance`
- `void displayAccountInfo()`: Print the account number, account holder name, and balance.
- `void withdraw(double amount)`: Subtract the withdrawal amount from the balance if
sufficient funds are available.
1
Simple Banking System
// Main method
public static void main(String[] args) {
// Creating an instance of BankAccount
BankAccount account = new BankAccount();
// Deposit money
account.deposit(500.00);
// Withdraw money
account.withdraw(200.00);
2
Simple Banking System
# Assignment Instructions :
1. Implement the `BankAccount` class with the specified attributes and methods.
2. In the `main` method, create an instance of `BankAccount`, initialize it with sample data,
and perform deposit and withdrawal operations.
3. Print the account details before and after the transactions to verify that the methods work
correctly.
4. Ensure that the program handles invalid withdrawal attempts gracefully by checking for
sufficient funds.
3
Simple Banking System
PART - 2
• Topics Covered
• Conditional statements
• Control statements
• Patterns
• Constructors
• Arrays
• OOP Principles (Encapsulation, Inheritance, Polymorphism)
• Multithreading
• Exception Handling
Task Steps
1. Extend the BankAccount Class:
• Add a constructor to initialize the account.
• Add methods to handle multiple transactions using arrays.
• Implement basic exception handling for invalid operations.
2. Add an Enhanced User Interface:
• Use control statements to build a menu-driven program.
• Implement conditional statements to navigate through the menu options.
3. Implement Multithreading:
• Simulate concurrent transactions using threads.
4. Pattern Generation:
• Add a method to display a simple pattern
SYNTAX:
import java.util.Scanner;
// Constructor
public BankAccount(String accountNumber, String accountHolderName, double initialBalance) {
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
this.balance = initialBalance;
this.transactions = new double[100]; // Initialize transaction array
this.transactionCount = 0;
}
4
Simple Banking System
@Override
public void run() {
try {
if (deposit) {
account.deposit(amount);
} else {
account.withdraw(amount);
}
} catch (InsufficientFundsException e) {
System.out.println(e.getMessage());
}
5
Simple Banking System
}
}
// Menu-driven program
while (true) {
System.out.println("\nBanking System Menu:");
System.out.println("1. Display Account Information");
System.out.println("2. Deposit Money");
System.out.println("3. Withdraw Money");
System.out.println("4. Display Transactions");
System.out.println("5. Display Pattern");
System.out.println("6. Simulate Concurrent Transactions");
System.out.println("7. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
account.displayAccountInfo();
break;
case 2:
System.out.print("Enter amount to deposit: ");
double depositAmount = scanner.nextDouble();
account.deposit(depositAmount);
break;
case 3:
System.out.print("Enter amount to withdraw: ");
double withdrawAmount = scanner.nextDouble();
try {
account.withdraw(withdrawAmount);
} catch (InsufficientFundsException e) {
System.out.println(e.getMessage());
}
break;
case 4:
account.displayTransactions();
break;
case 5:
account.displayPattern();
break;
case 6:
// Simulate concurrent transactions using multithreading
Thread t1 = new Thread(new TransactionRunnable(account, 200, true));
Thread t2 = new Thread(new TransactionRunnable(account, 300, false));
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case 7:
System.out.println("Exiting...");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
6
Simple Banking System
}
}
Assignment Instructions
Add a constructor to initialize the account with account number, holder name, and initial
balance.
Implement methods for deposit, withdrawal (with exception handling), and displaying
transactions.
Use conditional statements to handle user input and navigate through different operations.
• Multithreading:
• Exception Handling:
• Pattern Generation:
•
Testing:
Test the program with various inputs to ensure all features work correctly.