diff --git a/src/Customer.java b/src/Customer.java new file mode 100644 index 0000000..7796cfc --- /dev/null +++ b/src/Customer.java @@ -0,0 +1,13 @@ +public class Customer implements Runnable { + private final PastryShop shop; + + public Customer(PastryShop shop) { + this.shop = shop; + } + + @Override + public void run() { + //TODO + shop.get(); + } +} diff --git a/src/Main.java b/src/Main.java index 6dab25b..06df8af 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,12 @@ public class Main { public static void main(String[] args) { - System.out.println("Hello, threads!"); + PastryShop shop = new PastryShop(); + + Thread producer1 = new Thread(new PastryChef(shop)); + Thread consumer1 = new Thread(new Customer(shop)); + /* + producer1.start(); + consumer1.start(); + */ } } diff --git a/src/Pastry.java b/src/Pastry.java new file mode 100644 index 0000000..c6a819c --- /dev/null +++ b/src/Pastry.java @@ -0,0 +1,6 @@ +public class Pastry { + @Override + public String toString() { + return "I'm a pastry"; + } +} diff --git a/src/PastryChef.java b/src/PastryChef.java new file mode 100644 index 0000000..b8b2251 --- /dev/null +++ b/src/PastryChef.java @@ -0,0 +1,13 @@ +public class PastryChef implements Runnable { + private final PastryShop shop; + + public PastryChef(PastryShop shop) { + this.shop = shop; + } + + @Override + public void run() { + //TODO + shop.put(new Pastry()); + } +} diff --git a/src/PastryShop.java b/src/PastryShop.java new file mode 100644 index 0000000..a1084d0 --- /dev/null +++ b/src/PastryShop.java @@ -0,0 +1,23 @@ +import java.util.ArrayList; +import java.util.List; + +public class PastryShop { + private final List stock = new ArrayList<>(); + + int head = 0, tail = 0; // probably wrong + + public boolean put(Pastry pastry) { + //TODO + stock.add(tail, pastry); + return true; + } + + public Pastry get() { + //TODO + return stock.get(head); + } + + public int getStock() { + return stock.size(); + } +}