//package edu.unima.ky.parallel;

/** 
 * Finanz version B.
 * Multi threaded application generates transactions using
 * objects from KontoB and displays results.
 * Uses synchronized Konto which cannot become negative.
 * @author Heinz Kredel. 
 */ 
public class FinanzB {

    public static void main(String[] args) {
        
        for (int i=0; i < 10; i++) {
        KontoB a = new KontoB(-10.0);
        KontoB b = new KontoB(300.0);

        Thread t1 = new UeberweisungB(a,b,10.0); // a is the accont to get amount from.
        Thread t2 = new UeberweisungB(a,b,10.0); // b is account to add amount to.
        Thread t3 = new UeberweisungB(a,b,10.0); // 10.0 is the amount to transfer.
        Thread t4 = new UeberweisungB(b,a,50.0); 

        t1.start(); t2.start(); t3.start(); t4.start();

        System.out.println("Stand a = " + a.zeigeGeld() +
                           " Stand b = " + b.zeigeGeld() );

        try {
            t1.join(); t2.join(); t3.join(); t4.join();
        } catch(InterruptedException e ) { }

        System.out.println("Endstand a = " + a.zeigeGeld() +
                           " Endstand b = " + b.zeigeGeld() );
        }
    }

}
