Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import javax.lang.model.element.Element;
- public class Cliente extends Thread{
- private String nombre;
- private static int indice = 0;
- private Mostrador<Element> cola;
- private Random random = new Random();
- private int lim_superior_compra = 400;
- private int lim_inferior_compra = 200;
- private int lim_superior_llegada = 1500;
- private int lim_inferior_llegada = 800;
- public Cliente(Mostrador<Element> mostrador) {
- indice++;
- this.nombre = "Cliente "+ indice;
- this.cola = mostrador;
- }
- public void run() {
- try {
- Thread.sleep(random.nextInt(this.lim_inferior_llegada, this.lim_superior_llegada));
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- if(cola.noHayBizc()&&cola.noHayFact()) {
- System.out.println("Mostrador vacío, cliente "+indice+" esperando");
- try {
- wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- int bizcocho = cola.comprarBizcocho();
- int factura = cola.comprarFactura();
- System.out.println(this.nombre + " compró: bizcocho " + bizcocho + " y facura " + factura);
- try {
- Thread.sleep(random.nextInt(this.lim_inferior_compra, this.lim_superior_compra));
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement