import java.util.*;
import java.awt.*;
import java.io.*;
//runnable interface

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

    }
    public void run() {
        for(int count=0; count < 10; count++) {
            pTut.setCommonInteger(count);
            System.out.println("Produce integer produced  " + count);

        try {
            thread.sleep((int)(Math.random()*3000));
        }
        catch(InterruptedException exception) {
            System.err.println("Exception " + exception.toString());
        }
        }
    }
}
class ConsumeInteger implements Runnable{
    private CreateInteger cTut;
    private Thread thread;
    public ConsumeInteger(CreateInteger h) {
        cTut = h;
        thread= new Thread(this);
        thread.start();
    }
    public void run() {
        int IntValue=0;
        while(IntValue != 9) {
            try {
                thread.sleep((int)(Math.random()*3000));
            }
            catch(InterruptedException e) {
                System.err.println("Exception " + e.toString());
            }
            IntValue = cTut.getCommonInteger();
            System.out.println("Consume integer catched  " + IntValue);

        }
    }
}

class CreateInteger {
    private int CommonInteger;
    public void setCommonInteger(int IntValue) {CommonInteger = IntValue;}
    public int getCommonInteger() { return CommonInteger;}
}

public class CommonCellRunnable {
    public static void main(String[] args) {
        CreateInteger h= new CreateInteger();
        new ProduceInteger(h);
        new ConsumeInteger(h);
    }
}
