public class Tuberia{
    char almacen[]=new char[6];
    int siguiente=0;// Apunta donde hay que poner el elemento que entra
    boolean estaLlena=false;
    boolean estaVacia=true;
    // Metodo lanzar() mete un char en la bandeja
    synchronized void lanzar(char c){
        while(estaLlena){
            try{
                wait();
            }catch(Exception e){}
        }
        estaVacia=false;
        almacen[siguiente]=c;
        siguiente++;
        if(siguiente==6) estaLlena=true;
        notify();
    }
    
    synchronized char recoger(){
        while(estaVacia){
            try{
                wait();
            }catch(Exception e){}
        }
        estaLlena=false;
        siguiente--;
        if(siguiente==0) estaVacia=true;
        notify();
        return almacen[siguiente];
    }
    

}
