Question: In Java, write a program that uses ReentrantLock or ArrayBlockingQueue to simulate processing orders in a restaurant. After a chef prepared an order, a server
In Java, write a program that uses ReentrantLock or ArrayBlockingQueue to simulate processing orders in a restaurant. After a chef prepared an order, a server served it. Make sure to include some delay between preparing and serving orders. The program should include three classes Chef, Server and Main. Chef class is for preparing orders, Server class is for serving orders and Main class is for creating threads. In the Main class, creates 2 chef threads Chef John and Chef Mark, and 3 server threads Server Katie, Server Andrew and Server Emily. Print out the process while each thread is running see example 1. Each order should only be prepared and served once. After all threads finish running, print out the number of orders prepared by each chef and served by each server see example 2. Order preparation and serving is based on FIFO. The order list that the chef needs to prepare is attached as orderList.txt The following examples are samples of how the result may look like.
Example 1:
Chef Mark is preparing Neapolitan Pizza 92 Server Emily is serving Neapolitan Pizza 92 Chef John is preparing Cheese Burger 93 Server Katie is serving Cheese Burger 93 Chef Mark is preparing Cheese Burger 94 Server Katie is serving Cheese Burger 94 Chef John is preparing Neapolitan Pizza 95 Server Emily is serving Neapolitan Pizza 95 Chef Mark is preparing Cheese Burger 96 Server Katie is serving Cheese Burger 96 Chef Mark is preparing Neapolitan Pizza 97 Server Emily is serving Neapolitan Pizza 97 Chef John is preparing Neapolitan Pizza 98 Server Katie is serving Neapolitan Pizza 98 Chef John is preparing Cheese Burger 99 Server Andrew is serving Cheese Burger 99 Chef John is preparing Neapolitan Pizza 100 Server Katie is serving Neapolitan Pizza 100
Example 2:
Chef John finished preparing 49 orders including 18 burgers, 23 pizzas and 8 fish n chips
Chef Mark finished preparing 51 orders including 17 burgers, 22 pizzas and 12 fish n chips
Server Katie finished serving total 41 orders including 12 burgers, 24 pizzas and 5 fish n chips
Server Andrew finished serving 28 orders including 10 burgers, 10 pizzas and 8 fish n chips
Server Emily finished serving 31 orders including 13 burgers, 11 pizzas and 7 fish n chips
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
