Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BankAccount {
- private int accountNumber;
- private String accountHolderName;
- private double balance;
- // Constructor
- public BankAccount(int accountNumber, String accountHolderName) {
- this.accountNumber = accountNumber;
- this.accountHolderName = accountHolderName;
- this.balance = 0.0;
- }
- // Getters and Setters
- public int getAccountNumber() {
- return accountNumber;
- }
- public String getAccountHolderName() {
- return accountHolderName;
- }
- public double getBalance() {
- return balance;
- }
- // Methods
- public void deposit(double amount) {
- if (amount > 0) {
- balance += amount;
- System.out.println("Deposited: $" + amount);
- } else {
- System.out.println("Invalid deposit amount.");
- }
- }
- 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 withdrawal amount.");
- }
- }
- public void displayAccountInfo() {
- System.out.println("Account Number: " + accountNumber);
- System.out.println("Account Holder Name: " + accountHolderName);
- System.out.println("Balance: $" + balance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement