import java.util.*; /** Each BankAccount object represents a bank account for one specific user. * An account's balance should never be allowed to become negative. * @version 2048/03/12 */ public class BankAccount implements Comparable { String name; double balance = 0.0; ArrayList transactions; /** Constructs a new bank account with the given name. */ public BankAccount(String n) { name = n; transactions = new ArrayList(); } /** Compares this account to the other account, returns < 0, 0, or > 0. */ public int compareTo(BankAccount b) { if (name.equals(b.name)) return (int) (balance - b.balance); else return name.compareTo(b.name); } /** Getters and setter methods to get/set the balance and name. */ public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public String getName() { return name; } public void setName(String name) { this.name = name; } /** Deposits the given amount into this account. * @param amount how much to deposit */ public void deposit(double amount) { if (amount < 0) throw new IllegalArgumentException(); balance += amount; transactions.add("deposit of $" + amount); } /** Withdraws the given amount from this account. * @param amount how much to deposit */ public void withdraw(double amount) { if (amount < 0) throw new IllegalArgumentException(); balance -= amount + 0.25; // 25-cent transaction fee transactions.add("withdrawal of $" + amount); } /** Returns a text representation of this account, such as "Joe, $23.00". */ public String toString() { return "{Husky Bank Account for " + name + ", $" + balance + "}"; } }