/* AccountData.java */ import sortedlist.*; /** Implements a customer's account profile for the virtual teller machine. */ public class AccountData implements Keyable { /** Ceates a new account for customer `newName' and the acount * number 'num' with a $0 starting balance. */ public AccountData( String newName, int num ) { name = newName; number = num; balance = 0; } /** Returns true if 'this' account's number is less than the * argument's account number. */ public boolean lessThan(Keyable x) { if (number < ((AccountData) x).number) { return true; } else { return false; } } /** Returns the name of this account's owner. */ public String getOwner() { return name; } /** Returns a String of the account's number. */ public String toString() { return number + ""; } /** Returns the balance on this account. */ public int getBalance() { return balance; } /** Reduces the balance by the withdrawl amount, amt. */ public void withdraw( int amt ) { if( amt <= balance ) { balance -= amt; } else { System.out.println( "Error: Insufficient funds: " + amt ); } } /** Deposits `amt' into this account. */ public void deposit( int amt ) { if( amt >= 0 ) { balance += amt; } else { System.out.println( "Error: Tried to deposit less than 0: " + amt ); } } /** Returns this integer account number. */ public int getNumber() { return number; } /** Returns this account's integer account number * as the key to used in sorting and comparisons. */ public int getKey() { return number; } private String name; // customer name private int balance; // starting balance private int number; // account number }