CCCPaste

7af4b50689805

public class ProductorFactura extends Thread{
	private ArrayList  mostrador;
	private int num;
	private String[] types;
	private String type;
	private Random random;
	
	public ProductorFactura(ArrayList  mostrador) {
		this.mostrador=mostrador;
		this.num=0;
		this.types=new String[]{"con chocolate","simple","con coco"};
		this.type="";
		this.random=new Random();
	}
	
	public void run() {
	
		while(true) {
		try {
			int timeProduction=random.nextInt(1300-1000)+1000;
			int typeRandom=random.nextInt(this.types.length);
			
			Thread.sleep(timeProduction);
			synchronized(mostrador) {
				this.num++;
				this.type=types[typeRandom];
				Factura factura=new Factura(this.num,this.type);
				mostrador.add(factura);
				mostrador.notifyAll();
			}
			
		}catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		System.out.println("Factura("+num+", "+this.type+")"+" en mostrador");
		}
		
	}
	

}


public class ProductorBizcocho extends Thread{

	private ArrayList  mostrador;
	private int num;
	private String[] types;
	private String type;
	private Random random;
	
	public ProductorBizcocho(ArrayList  mostrador) {
		this.mostrador=mostrador;
		this.num=0;
		this.types=new String[]{"Cuadrado","chato","relleno"};
		this.type="";
		this.random=new Random();
	}
	
	public void run() {
	
		while(true) {
		try {
			int timeProduction=random.nextInt(600-400)+400;
			int typeRandom=random.nextInt(this.types.length);
			
			Thread.sleep(timeProduction);
			synchronized(mostrador) {
				this.num++;
				this.type=types[typeRandom];
				Bizcocho bizcocho=new Bizcocho(this.num,this.type);
				mostrador.add(bizcocho);
				mostrador.notifyAll();
			}
			
		}catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		System.out.println("Bizcocho("+this.num+", "+this.type+") en mostrador");
		}
		
	}
}