/** * A bank card. Each card is associated with an account. * Given a card, it is not possible to determine the account number. * It is possible to compare two cards and determine if they are for the same account. * * This is an implementation of a bank card as described in Kleinberg & Tardos, Chapter 5, Problem 3. * @author Barbara Lerner * */ public class BankCard { /** The account that the card is for. There is intentionally no getter or setter * for this field. (Pretend it is encrypted.) */ private int account; /** * Create a card for an account * @param acct the account the card is for */ public BankCard(int acct) { account = acct; } /** * Compare two cards. * @param o the other card * @return true if the other card and this card are for the same account. */ public boolean equals (Object o) { if (o == null) { return false; } if (!(o instanceof BankCard)) { return false; } BankCard other = (BankCard) o; return other.account == account; } }