Screenshot 2024-09-09 at 1.21.22 PM

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

package BankManagementSystem;

public class BankAccount {


private String accountNumber;
private String accountHolderName;
private double balance;

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

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

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

// Display account information


public void displayAccountDetails() {
System.out.println("Account Number: " + accountNumber);
System.out.println("Account Holder: " +
accountHolderName);
System.out.println("Balance: " + balance);
}

// Check balance method


public double getBalance() {
return balance;
}
}

You might also like