/** A deposit thread makes periodic deposits to a bank account. */ class DepositThread extends Thread { private BankAccount account; private double amount; private static final int REPETITIONS = 4; /** Constructs a deposit thread. @param anAccount the account into which to deposit money @anAmount the amount to deposit in each repetition */ public DepositThread(BankAccount anAccount, double anAmount) { account = anAccount; amount = anAmount; } public void run() { try { for (int i = 1; i <= REPETITIONS; i++) { account.deposit(amount); sleep((int)(Math.random()*100 + 1)); } } catch (InterruptedException exception) { } } }