import java.util.*;
import java.awt.*;
import java.io.*;
//runnable interfacei kullanarak

class UretInteger implements Runnable {
    private TutInteger pTut;
    private Thread thread;
    public UretInteger(TutInteger h) {
        pTut=h;
        thread = new Thread(this);
        thread.start();

    }
    public void run() {
        for(int count=0; count < 10; count++) {
            pTut.setOrtakInt(count);
            System.out.println("Ortak Integer " + count+" Olarak olusturuldu");

        try {
            thread.sleep((int)(Math.random()*3000));
        }
        catch(InterruptedException exception) {
            System.err.println("Exception " + exception.toString());
        }
        }
    }
}
class KullanInteger implements Runnable{
    private TutInteger cTut;
    private Thread thread;
    public KullanInteger(TutInteger h) {
        cTut = h;
        thread= new Thread(this);
        thread.start();
    }
    public void run() {
        int Intdegeri=0;
        while(Intdegeri != 9) {
            try {
                thread.sleep((int)(Math.random()*3000));
            }
            catch(InterruptedException e) {
                System.err.println("Exception " + e.toString());
            }
            Intdegeri = cTut.getOrtakInt();
            System.out.println("Kullan Integer " + Intdegeri+"degerini yakaladi");

        }
    }
}

class TutInteger {
    private int OrtakInt;
    public void setOrtakInt(int Intdegeri) {OrtakInt = Intdegeri;}
    public int getOrtakInt() { return OrtakInt;}
}

public class OrtakHucreR {
    public static void main(String[] args) {
        TutInteger h= new TutInteger();
        new UretInteger(h);
        new KullanInteger(h);
    }
}
