import java.util.*; // Interfaces II - problem #4 and 5 public class Account implements Comparable, Comparator, Cloneable{ private double balance; private byte id; private Owner owner; public Account(double b, byte i, Owner o) { balance = b; id = i; owner = o; } public void withdraw (int amount) { balance -= amount; } public void deposit (int amount) { balance += amount; } public byte getID(){ return id; } public double getBalance(){ return balance; } public Owner getOwner(){ return owner; } // compareTo - id public int compareTo(Object obj) { // This is a quick solution. Make sure you do type check first! Account ac = (Account)obj; byte id2 = ac.getID(); if (id > id2) return 1; else if (id == id2) return 0; else return -1; } // compare - balance public int compare(Object obj1, Object obj2) { Account ac1 = (Account)obj1; Account ac2 = (Account)obj2; double b1 = ac1.getBalance(); double b2 = ac2.getBalance(); if (b1 > b2) return 1; else if (b1 < b2) return -1; else return 0; } // clone public Object clone() { return new Account(balance, id, (Owner)owner.clone()); } } // Owner class Owner implements Comparable, Comparator, Cloneable{ private String name, address; public Owner(String name, String address) { this.name = name; this.address = address; } public String getN() { return name; } public String getA() { return address; } // compareTo public int compareTo(Object obj) { // This is a quick solution. Make sure you do type check first! Owner o2 = (Owner)obj; return getN().compareTo(o2.getN()); } // compare public int compare(Object obj1, Object obj2) { // This is a quick solution. Make sure you do type check first! Owner o1 = (Owner)obj1; Owner o2 = (Owner)obj2; // compare addresses return o1.getA().compareTo(o2.getA()); } // clone - deep clone public Object clone() { String n = new String(name); String add = new String(address); return new Owner(n, add); } }