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

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter10: Object-oriented Programming
Section: Chapter Questions
Problem 4RQ
icon
Related questions
Question

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

Runnable<<interface>>
Observable<<interface>>
+addObserver()
EspressoBarista
-propertyChangeSupportManager
CappuccinoBarista
-propertyChangeSupportManager
update
PropertyChangeListener<<interface>>
CoffeeShop
-HashMap<String, Integer> ingredients
Main
Transcribed Image Text:Runnable<<interface>> Observable<<interface>> +addObserver() EspressoBarista -propertyChangeSupportManager CappuccinoBarista -propertyChangeSupportManager update PropertyChangeListener<<interface>> CoffeeShop -HashMap<String, Integer> ingredients Main
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage