package atm;

/**
 * @author ssb
 */
public class SynchATMDemo {

	/**
	 * @param args
	 */
	public static void main ( String[] args ) {
		for ( int reps = 0 ; reps < 10 ; reps++ ) {
			System.out.println("---------------------");

			BankAccount account = new BankAccount(5000);

			System.out.println("starting balance: " + account.getBalance());

			Thread thread1 = new Thread(new SynchATM(account));
			thread1.start();

			Thread thread2 = new Thread(new SynchATM(account));
			thread2.start();

			try {
				thread1.join();
			} catch ( InterruptedException e ) {
				e.printStackTrace();
			}
			try {
				thread2.join();
			} catch ( InterruptedException e ) {
				e.printStackTrace();
			}

			System.out.println("account balance: " + account.getBalance()
			    + (account.getBalance() != 4000 ? "  *" : ""));
		}
	}
}
