// This example extends the Account class to have a user-defined // Exception thrown by the withdraw method. // public class AccountException { // instance variables String name; double balance; static double interestrate = .04; // constructor method is used to initialize instance variables public AccountException (String n, double b) { name = n; balance = b; } // accessor methods public String getname() { return name; } public double getbalance() { return balance; } // other methods public void withdraw (double amount) throws Exception { if ((balance - amount) > 0) { balance -= amount; } else throw new Exception ("Insufficient Funds"); } public void deposit (double amount) { balance += amount; } // returns monthly interest and updates balance public double monthactivity() { double interest = (balance * interestrate)/12; balance += interest; return interest; } }