**---------------------------** **-------Burrito.java--------** **---------------------------** import java.util.Scanner; public class Burrito { protected static int NoOfCustomers=0; protected static int NoOfServers=0; protected static int StorCapacity=0; protected static int ArrivalWindowMax=0; protected static int CookingSpeed=0; protected static int RegisterSpeed; protected static boolean advmode; static Scanner conIn = new Scanner(System.in); public static void main(String args[]) throws Exception { Scanner input = new Scanner(System.in); System.out.println("Welcome to Burrito Brothers restaurant"); System.out.println("\nChoose simulator mode: "); System.out.println("1: User Mode "); System.out.println("2: Test Mode (Advanced) "); int selectMode = Integer.parseInt(input.nextLine()); String adv=""; switch (selectMode) { case 1: // User Mode advmode=false; NoOfCustomers=5; NoOfServers=4; StorCapacity=5; ArrivalWindowMax=4000; CookingSpeed=1500; RegisterSpeed=1000; break; case 2: // Test Mode advmode=true; System.out.println("How many CUSTOMERS you want to generate?"); NoOfCustomers= Integer.parseInt(input.nextLine()); System.out.println("How many SERVERS you want to generate?"); NoOfServers= Integer.parseInt(input.nextLine()); System.out.println("Setup store capacity more then 1"); while (StorCapacity<2) { StorCapacity= Integer.parseInt(input.nextLine()); if (StorCapacity<2) System.out.println("store capacity must be more then 1"); } System.out.println("Setup customer generator frequency's upper limit (in MILLISECONDS) "); ArrivalWindowMax= Integer.parseInt(input.nextLine()); System.out.println("Setup Cooking time (in MILLISECONDS) for one burrito"); CookingSpeed= Integer.parseInt(input.nextLine()); System.out.println("Setup Register speed (in MILLISECONDS)"); RegisterSpeed= Integer.parseInt(input.nextLine()); adv="|---------- Waiting line and Register line -------------"; break; default: System.out.println("Error in mode choice. Terminating test."); return; } input.close(); System.out.println("------------- Customers activity --------------------|-------------------- Servers activity --------------"+adv); Store str = new Store(); for (int i=0; i3) { atCounter.redOrderSize(); // redusing ordersize by 3 buritos Store.getShop().Cooking(3,serverID); System.out.println("Customer #"+atCounter.getCustID() +" should reenter the line"); Store.getShop().CheckLine(atCounter,false); Store.getShop().semStartServing.release(); } else { Store.getShop().Cooking(atCounter.getOrderSize(),serverID); Store.getShop().GoToPay(atCounter); if (!Store.getShop().RegisterLine.isEmpty()&&Store.getShop().semRegister.tryAcquire()) { System.out.println(Store.getShop().space+"Server # "+serverID+" is on register"); Store.getShop().Register(); System.out.println(Store.getShop().space+"Server # "+serverID+" has left register"); } } } catch (InterruptedException e1) {e1.printStackTrace();} } public void run() { boolean working=true; while (working) { try { // try to serve customer if no customer in line wait if (Store.getShop().semStartServing.tryAcquire(Burrito.ArrivalWindowMax*Burrito.NoOfServers+100,TimeUnit.MILLISECONDS)) { FreeServer(); } else { working=false; // closing store System.out.println("Server #"+serverID+" finish his job" ); --ServersInStor; if (ServersInStor==0)System.out.println("Store is closed" ); } } catch (InterruptedException e) {e.printStackTrace(); } } } } **---------------------------** **------- Store.java --------** **---------------------------** import java.util.LinkedList; import java.util.concurrent.Semaphore; public class Store implements Runnable { private static Store Str = new Store(); private int CustInShop=0; protected int CustInLine=0; protected int custID=0; protected Customer line[]=new Customer[Burrito.StorCapacity]; protected LinkedList RegisterLine = new LinkedList(); protected Semaphore semCustInStore = new Semaphore(1); protected Semaphore semStartServing = new Semaphore(0); protected Semaphore semRegister = new Semaphore(1); protected Semaphore semRegisterLine = new Semaphore(1); protected Semaphore semCounter = new Semaphore(1); protected Semaphore semLine = new Semaphore(1); protected Semaphore semIngredients = new Semaphore(1); String space =String.format("%" + 55 + "s", " "); public static Store getShop() { return Str; } public void Welcome() { try { semCustInStore.acquire(); // only one customer can enter store at a time. ++custID; if(CustInShopline[0].getOrderSize()) line[1]=Cust; else { line[1]=line[0]; line[0]=Cust; } } else { for (int i=0; iline[i+1].getOrderSize()) { EnterLine(CustInLine+1,i+1,Cust); break; } if (i==CustInLine-2) line[i+2]=Cust; } } } } ++CustInLine; semLine.release(); } catch (InterruptedException e1) {e1.printStackTrace();} } public void EnterLine(int CustInLine, int Sortuntill, Customer Cust) { if (CustInLine==1) line[0]=Cust; else { for (int i=CustInLine-1; i>Sortuntill; --i) { if(Cust.getOrderSize() RegisterPrnt = new LinkedList(); String AtRegister=""; try { semRegisterLine.acquire(); RegisterLine.addLast(atCounter); //adding customer into register queue if (Burrito.advmode) { RegisterPrnt=RegisterLine; for (int i=0; i