commit 07932b80249c83d50744b62a8db1037d6a223787 Author: Ismail TAHA JANAN Date: Thu Jan 26 10:30:19 2023 +0100 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a346fd7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d33740e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/patisserie/main.class b/out/production/patisserie/main.class new file mode 100644 index 0000000..bfc1506 Binary files /dev/null and b/out/production/patisserie/main.class differ diff --git a/out/production/patisserie/model/Client.class b/out/production/patisserie/model/Client.class new file mode 100644 index 0000000..84ae771 Binary files /dev/null and b/out/production/patisserie/model/Client.class differ diff --git a/out/production/patisserie/model/Gateau.class b/out/production/patisserie/model/Gateau.class new file mode 100644 index 0000000..a362e10 Binary files /dev/null and b/out/production/patisserie/model/Gateau.class differ diff --git a/out/production/patisserie/model/Patisserie.class b/out/production/patisserie/model/Patisserie.class new file mode 100644 index 0000000..d314a46 Binary files /dev/null and b/out/production/patisserie/model/Patisserie.class differ diff --git a/out/production/patisserie/model/Patissier.class b/out/production/patisserie/model/Patissier.class new file mode 100644 index 0000000..410607d Binary files /dev/null and b/out/production/patisserie/model/Patissier.class differ diff --git a/patisserie.iml b/patisserie.iml new file mode 100644 index 0000000..fe594be --- /dev/null +++ b/patisserie.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main.java b/src/main.java new file mode 100644 index 0000000..9d6c74b --- /dev/null +++ b/src/main.java @@ -0,0 +1,32 @@ +import model.Client; +import model.Patisserie; +import model.Patissier; + +class main { + public static void main(String[] args) throws InterruptedException { + + Patisserie pp = new Patisserie(); + + Client c = new Client(pp); + Patissier p = new Patissier(pp); + + + for (int i = 0; i < 5; i++){ + Thread t = new Thread(p); + t.start(); + } + + for (int i = 0; i < 5; i++){ + Thread t = new Thread(c); + t.start(); + + + } + while (true){ + System.out.println("stock "+pp.gateauList.size()); + System.out.flush(); + } + + } +} + diff --git a/src/model/Client.java b/src/model/Client.java new file mode 100644 index 0000000..b0337ea --- /dev/null +++ b/src/model/Client.java @@ -0,0 +1,28 @@ +package model; + +public class Client implements Runnable{ + + Patisserie patisserie; + + public Client(Patisserie p ){ + patisserie = p; + }; + + + @Override + public void run() { + while (true){ + try { + Thread.sleep(2000); + if (patisserie.gateauList.size()>0){ + + + //System.out.println("client mangé il reste : "+ patisserie.gateauxReste()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + patisserie.mange();} + } + + } +} diff --git a/src/model/Gateau.java b/src/model/Gateau.java new file mode 100644 index 0000000..0dd1595 --- /dev/null +++ b/src/model/Gateau.java @@ -0,0 +1,9 @@ +package model; + +public class Gateau { + public int name; + + public Gateau(){ + name = (int)(Math.random()); + } +} diff --git a/src/model/Patisserie.java b/src/model/Patisserie.java new file mode 100644 index 0000000..a28e9ae --- /dev/null +++ b/src/model/Patisserie.java @@ -0,0 +1,25 @@ +package model; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Patisserie { + public List gateauList = new ArrayList(); + + + synchronized void depose(){ + gateauList.add(new Gateau()); + } + + synchronized void mange(){ + gateauList.remove(0); + } + + synchronized int gateauxReste() { + return gateauList.size(); + } + + + +} diff --git a/src/model/Patissier.java b/src/model/Patissier.java new file mode 100644 index 0000000..baa729d --- /dev/null +++ b/src/model/Patissier.java @@ -0,0 +1,29 @@ +package model; + +public class Patissier implements Runnable{ + + Patisserie patisserie; + + public Patissier(Patisserie p ){ + patisserie = p; + }; + + @Override + public void run() { + while (true){ + try { + + + if (patisserie.gateauList.size()<20){ + Thread.sleep(1000); + patisserie.depose(); + } + + //System.out.println("gateaux ajoute le stock est : "+ patisserie.gateauxReste()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + } +}