From f64b34674944f67fdc8eff8198f729b51cb182ec Mon Sep 17 00:00:00 2001 From: Minh VU Date: Thu, 28 Nov 2024 09:40:01 +0100 Subject: [PATCH] client update --- src/Client.java | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Client.java b/src/Client.java index ec4154c..fc6f745 100644 --- a/src/Client.java +++ b/src/Client.java @@ -1,3 +1,31 @@ +import java.util.Random; + public class Client extends Thread { - + private int MAX_PORTION = 100; + protected Compartiment compartiment; + + public Client (Compartiment c){ + this.compartiment=c; + } + + public void prendre_portion(Compartiment compartiment){ + synchronized(compartiment){ + int r =new Random().nextInt(MAX_PORTION); + try{ + while(r > compartiment.getQuantite()){ + this.wait(); + } + } catch (InterruptedException e){ + throw new RuntimeException(e); + } + compartiment.servir(r); + int temps_servir =new Random().nextInt(300 - 200) + 200; + //this.wait(temps_servir); + compartiment.notifyAll(); + } + } + + public void entrer(){ + + } }