// BankAccount.java /** * BankAccount represents a single named deposit account at a bank. */ public class BankAccount { // Member variables: /** The current balance of this BankAccount. */ private double myBalance = 0.0; /** The identifying name of this BankAccount. */ private String myName = ""; // Constructors: /** * Creates a BankAccount. * This constructor is declared private to prohibit creation * of an account without a name and initial balance. */ private BankAccount() { } /** * Creates a BankAccount. * @param aName The name for this account. * @param aBalance The initial balance in this account. */ public BankAccount( String aName, double aBalance) { this.myBalance = aBalance; this.myName = aName; } // Methods: /** * Returns the current balance of this account. */ public double getBalance() { return( myBalance);} /** * Returns the identifying name of this account. */ public String getName() { return( myName);} /** * Deposits money in the account. * @param money The amount of money to be deposited. */ public void deposit( double money) { if( money >= 0) { myBalance += money; } } /** * Withdraws money from this account. * If an overdraft is attempted, all current money is withdrawn. * @param money The amount of money to be withdrawn. * @return The amount of money actually withdrawn. */ public double withdraw( double money) { if( money <=0) return( 0);// can't withdraw a negative double actual = 0; if( money > myBalance) { actual = myBalance; } else { actual = money; } myBalance -= actual; return( actual); } }