/** * This class represents a bank account * * @author alchambers */ public class BankAccount { private String owner; // the name of the person who owns the account private double balance; private int accountId; /** * Constructs an account with an initial balance * @param b initial balance * @param id account id number */ public BankAccount(String owner, double balance, int accountId){ this.owner = owner; this.balance = balance; this.accountId = accountId; } /** * Constructs an account with an initial balance of 0 * @param id account id number */ public BankAccount(String owner, int accountId){ balance = 0; this.owner = owner; this.accountId = accountId; } /** * Withdraws money from the account * @param amountOut the amount to be withdrawn * @return current balance */ public double withdraw(double amountOut){ if(amountOut > balance){ System.out.println("Withdrawal failed: insufficient funds"); } else{ balance = balance - amountOut; } return balance; } /** * Deposits money into the account * @param amountIn the amount to be deposited * @return current balance */ public double deposit(double amountIn){ balance = balance + amountIn; return balance; } /** * Returns the current balance * @return the account balance */ public double getBalance(){ return balance; } /** * Returns the account id number * @return the account id number */ public int getAccountId(){ return accountId; } /** * Return true if this account has the same id as the other account * @param other The other bank account * @return true if this account and other account have same id, false otherwise */ public boolean equals(BankAccount other){ return accountId == other.getAccountId(); } /** * Returns a string representation of the account * @param A string representation of the bank account */ public String toString(){ return "[owner=" + owner + ", balance=" + balance + "]"; } }