FileDocCategorySizeDatePackage
Bank1.javaAPI DocExample2236Sun Feb 13 16:52:30 GMT 2000None

Bank

public class Bank extends Object

Fields Summary
public static final int
NO_ACCS
public static final int
INIT_BAL
private int
noTransacts
private int[]
account
Constructors Summary
public Bank()

   
    
     account = new int[ NO_ACCS ];
      for( int i = 0; i < account.length; i++ )
      {  account[i] = INIT_BAL;
      }
      noTransacts = 0;
      currentState();
   
Methods Summary
public voidcurrentState()

  int bal = 0;
      for( int i=0; i < account.length; i++ )
      {  bal += account[i];
      }
      System.out.println( "Transactions:\t" + noTransacts +
                          "\tTotal balance:\t" + bal );
   
public static voidmain(java.lang.String[] args)

  Bank theBank = new Bank();
      for( int i=0; i < NO_ACCS; i++ )
      {  new TransactionGenerator( theBank, i ).start();
      }
      // Remove comment for Linux to simulate
      // the time-slicing found in WindowsXX
       new Switcher(); 
   
public voidtransfer(int amount, int from, int to)

  while( account[from] < amount )
      {  try
         {  Thread.sleep(5);
         }
         catch( InterruptedException e ) {}
      }
      account[from] -= amount;
      account[to] += amount;
      noTransacts += 1;
      if( noTransacts%1000 == 0 )
      {  currentState();
      }