// This example extends the Account class to have a user-defined // Exception thrown by the withdraw method. // Nancy McCracken 3/14/97 public class AccountException { // instance variables String name; float balance; static float interestrate = .04F; // constructor method is used to initialize instance variables public AccountException (String n, float b) { name = n; balance = b; } // accessor methods public String getname() { return name; } public float getbalance() { return balance; } public int getbalancedollars() { return (int)Math.floor(balance); } public int getbalancecents() { return (int)(balance - Math.floor(balance))*100 ; } // throws an exception of type Exception, constructed with // user-defined message public void withdraw (float amount) throws Exception { if ((balance - amount) > 0) { balance -= amount; } else throw new Exception("Insufficient Funds"); } public void deposit (float amount) { balance += amount; } public void monthactivity() { balance = balance + (balance * interestrate)/12; } }