1 /**
2 A withdraw runnable makes periodic withdrawals from a bank account.
3 */
4 public class WithdrawRunnable implements Runnable
5 {
6 private static final int DELAY = 1;
7 private BankAccount account;
8 private double amount;
9 private int count;
10
11 /**
12 Constructs a withdraw runnable.
13 @param anAccount the account from which to withdraw money
14 @param anAmount the amount to deposit in each repetition
15 @param aCount the number of repetitions
16 */
17 public WithdrawRunnable(BankAccount anAccount, double anAmount,
18 int aCount)
19 {
20 account = anAccount;
21 amount = anAmount;
22 count = aCount;
23 }
24
25 public void run()
26 {
27 try
28 {
29 for (int i = 1; i <= count; i++)
30 {
31 account.withdraw(amount);
32 Thread.sleep(DELAY);
33 }
34 }
35 catch (InterruptedException exception) {}
36 }
37 }
38