class OrtakHucre
{
    public static void main(String args[])
    {
        Tutinteger h=new Tutinteger();
        Uretinteger p=new Uretinteger(h);
        Kullaninteger c= new Kullaninteger(h);

        p.start();
        c.start();
    }
}

class Uretinteger extends Thread
{
    private Tutinteger pTut;

    public Uretinteger(Tutinteger h)
    {
        pTut=h;
    }

    public void run() 
    {
        for(int count=0; count<10; count++)
        {
            pTut.setOrtakint(count);
            System.out.println("Ortakinteger "+count+" degerini uretti");

           try{
              sleep( (int) (Math.random()*5000 ) );
              }
              catch(InterruptedException e)
                {
                System.err.println("Exeption "+e.toString());
                }
        }
    }
}

class Kullaninteger extends Thread
{
    private Tutinteger cTut;

    public Kullaninteger(Tutinteger h)
    {
        cTut=h;
    }

    public void run() 
    {
        int intdegeri=0;


        while (intdegeri !=9)
        {
            try{
                sleep( (int) (Math.random()*5000));
               }
            catch(InterruptedException e)
            {
                System.err.println("Exeption "+e.toString());
            }
        intdegeri=cTut.getOrtakint();
        System.out.println("Kullan integer "+intdegeri+" degerini okudu");

       }
    }
}

class Tutinteger
{
    private int Ortakint;

    public void setOrtakint(int intdegeri)
    {
        Ortakint=intdegeri;
    }

    public int getOrtakint()
    {
        return Ortakint;
    }
}

