// CSE 142, Autumn 2010, Jessica Miller // A modified version of the BankAccount that we did earlier in the quarter. // This version has a static field that allows the BankAccount class to // assign each BankAccount object a unique number. public class BankAccount { private static final double MIN_BALANCE = 5.00; private static int numAccountsCreated = 0; // fields - the variables in each object private int number; private double balance; private int ssn; private String name; private int pin; private String address; public BankAccount(String initialName) { name = initialName; balance = MIN_BALANCE; numAccountsCreated++; number = numAccountsCreated; } public int getAccountNumber() { return number; } // read-only access to account balance public double getBalance() { return balance; } // Deposits the given amount from this bank account. // If the amount is negative, the transaction is aborted. public void deposit(double amount) { if (amount > 0.0) { balance = balance + amount; } } // Withdraws the given amount from this bank account. // If the amount is negative or the account does not have that much money, // the transaction is aborted. public void withdraw(double amount) { if (amount > 0.0 && amount <= balance - MIN_BALANCE) { balance = balance - amount; } } // Returns a String representation of this bank account object, // so that it can be printed. // Example: "Marty: $5.25" public String toString() { return name + ": $" + balance; } }