// CSE 142, Autumn 2010, Marty Stepp // This class defines a new type of objects called BankAccount. // Each BankAccount object represents one user's account at a bank, // including the account balance, personal info, and so on. // BankAccount objects include behavior for making transactions on the account // such as deposits and withdrawals. public class BankAccount { private static final double MIN_BALANCE = 5.00; // 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; } // 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; } }