Write a code in Java Programming Your task is to simulate a coffee shop using the observer pattern (do not use the deprecate one). The coffee shop serves two types of coffee: espresso and cappuccino. The shop has two baristas, EspressoBarista and CappuccinoBarista. EspressoBarista generates random espresso orders between 1 and 3 every 2 seconds, while CappuccinoBarista generates random cappuccino orders between 1 and 3 every 3 seconds. The UML design diagram is shown below. Property ChangeListenerfac Observablenerfacto Coffeeshop HashMap Sting, integer> ingredients ExpresssCartate The CoffeeShop class holds the current stock of ingredients and the CoffeeShop constructor initializes the count for each ingredient. The required ingredients for each type of coffee are as follows: • Espresso: 1 shot of espresso, 1 ounce of milk Cappuccino: 1 shot of espresso, 2 ounces of m
Write a code in Java Programming
Your task is to simulate a coffee shop using the observer pattern (do not use the deprecate one). The coffee shop serves two types of coffee: espresso and cappuccino. The shop has two baristas, EspressoBarista and CappuccinoBarista.
EspressoBarista generates random espresso orders between 1 and 3 every 2 seconds, while CappuccinoBarista generates random cappuccino orders between 1 and 3 every 3 seconds.
The UML design diagram is shown below.
Property ChangeListenerfac Observablenerfacto Coffeeshop HashMap Sting, integer> ingredients ExpresssCartate
The CoffeeShop class holds the current stock of ingredients and the CoffeeShop constructor initializes the count for each ingredient. The required ingredients for each type of coffee are as follows:
• Espresso: 1 shot of espresso, 1 ounce of milk
Cappuccino: 1 shot of espresso, 2 ounces of milk, 1 ounce of foam
If an order cannot be fulfilled because there are not enough ingredients, a warning message should be printed.
Please ensure that the printing format matches the provided example output.
Given:
public static void main(String[] args) {
EspressoBarista eb = new EspressoBarista();
CappuccinoBarista cb= new CappuccinoBarista();
CoffeeShop coffeeShop = new CoffeeShop(20, 20, 10, 10); eb.addObserver(coffeeShop);
cb.addObserver(coffeeShop);
new Thread(eb).start();
new Thread(cb).start();
Print:
Remaining ingredients are (Milk=10, Foam=10, Espresso=20}
Receive 1 orders from espresso barista
Remaining ingredients are (Milk=9, Foam=10, Espresso=19]
=======================================================
Receive 3 orders from cappuccino barista
Remaining ingredients are {Milk=3, Foam=7, Espresso=16}
=======================================================
Receive 2 orders from espresso barista
Remaining ingredients are {Milk=1, Foam=7, Espresso=14}
======================================================
Receive 1 orders from cappuccino barista, but not enough ingredients Receive 1 orders from espresso barista
Remaining ingredients are {Milk=0, Foam=7, Espresso=13}
Receive 2 orders from cappuccino barista, but not enough ingredients Receive 2 orders from espresso barista, but not enough ingredients Receive 3 orders from cappuccino barista, but not enough ingredients
Trending now
This is a popular solution!
Step by step
Solved in 3 steps