/**
 * Class to represent ATM which withdraws money from a bank
 * Written 11/26/99 by Kim Bruce
 * Changed 3/16/00 by Barbara Lerner
 * Introduced a random pause in the critical section to make interference more probable.
 * Changed 5/7/02 by Jim Teresco to include a longer delay to better see
 * what is happening
 */

import java.awt.*;
import java.awt.event.*;
import objectdraw.*;

public class ATM extends ActiveObject {

  private Account account;
  private int change;         	// Amount of each transaction
  private Label info;		// Where write description of transactions
  private int total = 0;

  // Store parameters and start running
  public ATM(Account anAccount, int aChange, Label aInfo) {
    account = anAccount;
    change = aChange;
    info = aInfo;
    start();
  }

  // Repeatedly withdraw "change" from account at bank.
  public void run() {
    for (int i = 0; i < 10; i++) {

      account.changeBalance(change);

      total = total + change;
      info.setText("" + total);
      pause(400);
    }
  }
}