// Allison Obourn, CSE 142 // A bank account object which has a balance that can be changed // by deposits and withdrawals. public class BankAccount { private double balance; private int transactionNumber; private String owner; private int accountNumber; private static int numAccounts = 0; // Constructs a bank acount with a given balance and name public BankAccount(double startingBalance, String name) { balance = startingBalance; owner = name; numAccounts++; accountNumber = numAccounts; } // Returns the balance public double getBalance() { return balance; } // Withdraws money from the bank account. Fails if the balance is less // than the money to withdraw public void withdraw(double money) { if (balance >= money) { balance -= money; } } // Deposits money into the bank account. Fails if amount is negative. public void deposit(double money) { if (money > 0) { balance += money; } } // Returns the account id number public int getAccountNumber() { return accountNumber; } // Returns the number of accounts that have been created public static int getNumAccounts() { return numAccounts; } }