public class BankAccount implements Comparable { public void deposit(double amount) { balance = balance + amount; } public void withdraw(double amount) { balance = balance - amount; } public double getBalance() { return balance; } public int getAccount() { return accountNum; } public int getLastAccount() { return lastAccountNum; } public BankAccount() { this(0); } public BankAccount(double b) { balance = b; lastAccountNum++; accountNum = lastAccountNum; } // clone method public Object clone() { // Make a new account with an identical balance BankAccount copy = new BankAccount(balance); return copy; } // equals method public boolean equals(Object otherObject) { if (otherObject instanceof BankAccount) { BankAccount other = (BankAccount) otherObject; return balance == other.balance; } // Accounts are equal if they have the same balance else return false; } // toString method public String toString() { return "BankAccount[balance="+ balance+ "]"; } public int compareTo(Object other) { BankAccount b = (BankAccount) other; return (int) (this.getBalance() - b.getBalance()); } private double balance; private int accountNum; private static int lastAccountNum = 0; // Static }