/** * BankAccount: a generic bank account. */ public class BankAccount { // instance variables private String accountName; // Account holder's name private int accountNumber; // Account number private double balance; // current balance in dollars // class invariant: accountName != null /** * Construct a new BankAccount with the given name, number, * and initial balance */ public BankAccount(String name, int number, double initialBalance) { this.accountName = name; this.accountNumber = number; this.balance = initialBalance; } /** * Deposit money into the account. * * @param amount dollars to be added to the account */ public void deposit(double amount) { this.balance += balance + amount; } /** * Withdraw money from this account (may leave account balance * negative if insufficient funds). * @param amount dollars to be withdrawn from the account */ public void withdraw(double amount) { this.balance -= amount; } /** Return the name associated with this account */ public String getName() { return this.accountName; } /** Return the account number of this account */ public int getNumber() { return this.accountNumber; } /** Return the current balance of this account */ public double getBalance() { return this.balance; } /** Return a string representation of this BankAccount */ public String toString() { return "BankAccount[" + accountName + ", " + accountNumber + ", " + balance + "]"; } }