Question
******Need Main Method for this code to run and show the below output PLEASE********* import java.util.concurrent.Semaphore; public class RestaurantSimulation { private static final int MAX_BURGERS
******Need Main Method for this code to run and show the below output PLEASE*********
import java.util.concurrent.Semaphore;
public class RestaurantSimulation {
private static final int MAX_BURGERS = 5;
private static final int MAX_FRIES = 5;
private static final int MAX_MEALS = 3;
private static Semaphore kitchenTable = new Semaphore(MAX_BURGERS + MAX_FRIES);
private static Semaphore readyTable = new Semaphore(0);
private static Semaphore burgerMutex = new Semaphore(1);
private static Semaphore friesMutex = new Semaphore(1);
private static Semaphore mealsMutex = new Semaphore(1);
private static int burgersLeft = 20;
private static int friesLeft = 20;
private static int mealsLeft = 0;
private static class BurgerChef extends Thread {
@Override
public void run() {
while (true) {
try {
// Wait for kitchen table to have space for a burger
kitchenTable.acquire();
// Make a burger
burgerMutex.acquire();
burgersLeft--;
System.out.println("[Action] BurgerChef add a burger on the kitchen table");
System.out.println("[Status] burgers left: " + burgersLeft);
burgerMutex.release();
// Check if there's a set of fries on the kitchen table
if (kitchenTable.availablePermits()
System.out.println("[Action] BurgerChef makes Burger and Fries and place it on the ready table");
readyTable.acquire();
mealsMutex.acquire();
mealsLeft++;
System.out.println("[Status] burgers left: " + burgersLeft + ", fries left: " + friesLeft + ", meals left: " + mealsLeft);
mealsMutex.release();
System.out.println("--------------------");
kitchenTable.release();
} else {
kitchenTable.release();
Thread.sleep(3000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private static class FriesChef extends Thread {
@Override
public void run() {
while (true) {
try {
// Wait for kitchen table to have space for fries
kitchenTable.acquire();
// Make a set of fries
friesMutex.acquire();
friesLeft--;
System.out.println("[Action] FriesChef add a fries on the kitchen table");
System.out.println("[Status] fries left: " + friesLeft);
friesMutex.release();
// Check if there's a burger on the kitchen table
if (kitchenTable.availablePermits()
System.out.println("[Action] FriesChef makes Burger and Fries and place it on the ready table");
readyTable.acquire();
mealsMutex.acquire();
mealsLeft++;
System.out.println("[Status] burgers left: " + burgersLeft + ", fries left: " + friesLeft + ", meals left: " + mealsLeft);
mealsMutex.release();
System.out.println("--------------------");
kitchenTable.release();
} else {
kitchenTable.release();
Thread.sleep(2000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private static class Waitress extends Thread {
@Override
public void run() {
while (true) {
try {
// Wait for a meal to be ready
readyTable.acquire();
// Serve a meal
mealsMutex.acquire();
mealsLeft--;
System.out.println("[Action] Waitress serve a meal");
System.out.println("[Status] meals left:");
Question: Burgers and Fries (100 points) After the pandemic, you decide to open a fast-food restaurant. Since this is a start-up business, you only focus on selling one meal: burger and fries. After a couple of days of observation, you found that you need to have at least one chef for making the burger and one chef for making fries for serving customers. In this assignment, you need to simulate this restaurant using the Java thread you learn in the class. Please start your assignment using the template I provide. In the restaurant, you have one burger chef, one fries chef, and one waitress. In this simulation, the burger chef can produce a burger every 3 seconds, and the fries chef can produce a set of fries every 2 seconds. There is a kitchen table between the two chefs. The table is used to temporarily place the burgers or fries. Since the table has a limited size, it only allows having a maximum of 5 burgers and 5 sets of fries (total 10 food items here). For example, If the table has 5 burgers, the burger chef should start waiting until the table has a free space. Next, If the kitchen table has at least one burger and one set of fries, either the burger chef or fries chef can combine them to make a combo and place it on the ready table. Note that in your simulation, you need to show me who makes the combo. Finally, the waitress can serve these combos to customers from the ready table. The average serving time for one customer is 10 seconds, but the ready table can only have a maximum of 3 meals. Thus, a chef should wait until ready table are available before making a new combo. All wait times should take 1 second, this apply to, for example, the waitress' waiting time if there is no meal on the ready table or chef's waiting time if either the ready table or the kitchen table are not available. To get full marks, you need to: 1. Follow the printing format. (e.g., draw a horizontal line when making a combo or serving a meal) 2. Follow the simulation logic. 3. Correctly show the action and status. 4. The program should never end. [Action] Frieschef add a fries on the kitchen table [Status] fries left: 1 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 1 [Action] Burgerchef makes Burger and Fries and place it on the ready table [Status] burgers left: , fries left: 0 , meals left: 1 [Action] Waitress serve a meal [Status] meals left: 0 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 1 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 1 [Action] Burgerchef makes Burger and Fries and place it on the ready table [Status] burgers left: 0 , fries left: 0 , meals left: 1 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 1 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 2 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 1 [Action] BurgerChef makes Burger and Fries and place it on the ready table [Status] burgers left: 0, fries left: 1, meals left: 2 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 2 [Action] Burgerchef add a burger on the kitchen table [Status] burgers left: 1 [Action] Burgerchef makes Burger and Fries and place it on the ready table [Status] burgers left: 0 , fries left: 1, meals left: 3 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 2 [Action] Waitress serve a meal [Status] meals left: 2 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 3 [Action] Burgerchef add a burger on the kitchen table [Status] burgers left: 1 [Action] BurgerChef makes Burger and Fries and place it on the ready table [Status] burgers left: 0, fries left: 2, meals left: 3 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 3 [Action] Burgerchef add a burger on the kitchen table [Status] burgers left: 1 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 4 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 5 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 2 Question: Burgers and Fries (100 points) After the pandemic, you decide to open a fast-food restaurant. Since this is a start-up business, you only focus on selling one meal: burger and fries. After a couple of days of observation, you found that you need to have at least one chef for making the burger and one chef for making fries for serving customers. In this assignment, you need to simulate this restaurant using the Java thread you learn in the class. Please start your assignment using the template I provide. In the restaurant, you have one burger chef, one fries chef, and one waitress. In this simulation, the burger chef can produce a burger every 3 seconds, and the fries chef can produce a set of fries every 2 seconds. There is a kitchen table between the two chefs. The table is used to temporarily place the burgers or fries. Since the table has a limited size, it only allows having a maximum of 5 burgers and 5 sets of fries (total 10 food items here). For example, If the table has 5 burgers, the burger chef should start waiting until the table has a free space. Next, If the kitchen table has at least one burger and one set of fries, either the burger chef or fries chef can combine them to make a combo and place it on the ready table. Note that in your simulation, you need to show me who makes the combo. Finally, the waitress can serve these combos to customers from the ready table. The average serving time for one customer is 10 seconds, but the ready table can only have a maximum of 3 meals. Thus, a chef should wait until ready table are available before making a new combo. All wait times should take 1 second, this apply to, for example, the waitress' waiting time if there is no meal on the ready table or chef's waiting time if either the ready table or the kitchen table are not available. To get full marks, you need to: 1. Follow the printing format. (e.g., draw a horizontal line when making a combo or serving a meal) 2. Follow the simulation logic. 3. Correctly show the action and status. 4. The program should never end. [Action] Frieschef add a fries on the kitchen table [Status] fries left: 1 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 1 [Action] Burgerchef makes Burger and Fries and place it on the ready table [Status] burgers left: , fries left: 0 , meals left: 1 [Action] Waitress serve a meal [Status] meals left: 0 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 1 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 1 [Action] Burgerchef makes Burger and Fries and place it on the ready table [Status] burgers left: 0 , fries left: 0 , meals left: 1 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 1 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 2 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 1 [Action] BurgerChef makes Burger and Fries and place it on the ready table [Status] burgers left: 0, fries left: 1, meals left: 2 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 2 [Action] Burgerchef add a burger on the kitchen table [Status] burgers left: 1 [Action] Burgerchef makes Burger and Fries and place it on the ready table [Status] burgers left: 0 , fries left: 1, meals left: 3 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 2 [Action] Waitress serve a meal [Status] meals left: 2 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 3 [Action] Burgerchef add a burger on the kitchen table [Status] burgers left: 1 [Action] BurgerChef makes Burger and Fries and place it on the ready table [Status] burgers left: 0, fries left: 2, meals left: 3 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 3 [Action] Burgerchef add a burger on the kitchen table [Status] burgers left: 1 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 4 [Action] Frieschef add a fries on the kitchen table [Status] fries left: 5 [Action] BurgerChef add a burger on the kitchen table [Status] burgers left: 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started