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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education