public void run() { Foodistan fdistan = Foodistan.getfoodistan(); while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) { for (int l = 0; l < fdistan.getChefs().size(); l++) { Chef c = fdistan.chefs.get(l); if (c.getcStatus() == chefStatus.FREE) { fdistan.getChefs().get(l).cookItem(ItemType.BURGER); } } } }
public void run() { Foodistan fdistan = Foodistan.getfoodistan(); while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) { for (int k = 0; k < fdistan.getChefs().size(); k++) { Chef c = fdistan.chefs.get(k); // decreasing speed if (fdistan.getInv().items.size() > fdistan.getBurgerNeeded()) { long changeUpTime = c.getBackUpCookTime() * 2; if (changeUpTime <= 3600000) { fdistan.chefs.get(k).setBackUpCookTime(changeUpTime); } else { fdistan.chefs.get(k).setBackUpCookTime(fdistan.chefs.get(k).getDefaultCookTime()); } } // increasing speed if (fdistan.getInv().items.size() < fdistan.getBurgerNeeded()) { long changeDownTime = c.getBackUpCookTime() / 2; if (changeDownTime > 1) { fdistan.chefs.get(k).setBackUpCookTime(changeDownTime); } } } } }
public void run() { Foodistan fdistan = Foodistan.getfoodistan(); while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) { for (int k = 0; k < fdistan.getChefs().size(); k++) { Chef c = fdistan.chefs.get(k); if (c.getcStatus() == chefStatus.SPEEDUPDATE) { fdistan.chefs.get(k).setCurrentCookTime(fdistan.chefs.get(k).getBackUpCookTime()); fdistan.chefs.get(k).setcStatus(chefStatus.FREE); } } } }
public void run() { Foodistan fdistan = Foodistan.getfoodistan(); while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) { for (int k = 0; k < fdistan.getChefs().size(); k++) { Chef c = fdistan.chefs.get(k); if (((c.getcStatus() == chefStatus.BUSY) && (c.getCookStartTime() + (c.getCurrentCookTime())) < System.currentTimeMillis())) { Item itm = new Item(ItemType.BURGER); fdistan.getMg().refillInventory(itm); fdistan.chefs.get(k).setcStatus(chefStatus.SPEEDUPDATE); fdistan .chefs .get(k) .setCurrentCookTime(fdistan.chefs.get(k).getCurrentCookTime() * fdistan.getSpeedUp()); } } } }
/** @param args */ public static void main(String[] args) { // to parse the input with validation checks Foodistan fdistan = getfoodistan(); // java fs {F1, F2, F3 ...} {C1, C2, C3 .....} n // ; int curl = 0; int curlC = 0; String delimiter = ","; try { for (String s : args) { String[] temp = s.split(delimiter); if (temp[0].equalsIgnoreCase("{")) { curl++; } if (temp[0].equalsIgnoreCase("}")) { curlC++; } if (((!temp[0].equalsIgnoreCase("{"))) && curl == 1 && curlC != 1) { // System.out.println(s); if (Integer.parseInt(temp[0]) < 0 || Integer.parseInt(temp[0]) > 100) { System.out.println("Invalid Foodie Discount" + temp[0]); System.exit(1); } Foodie fd1 = new Foodie(Integer.parseInt(temp[0]), ItemType.BURGER, 300000l); fdistan.foodies.add(fd1); } if (((!temp[0].equalsIgnoreCase("}")) && (!s.equalsIgnoreCase("{"))) && curl == 2 && curlC != 2) { // System.out.println(s+"hello"); if (Long.parseLong(temp[0]) <= 0) { System.out.println("Invalid chef cooking speed " + temp[0]); System.exit(1); } long cookTime = 3600000l / Long.parseLong(temp[0]); Chef cf = new Chef(ItemType.BURGER, cookTime); fdistan.chefs.add(cf); } if (curlC == 2 && !temp[0].equalsIgnoreCase("}")) { if (temp[0] == "" || Long.parseLong(temp[0]) <= 0) { System.out.println("Please enter correct time"); System.exit(1); } Foodistan.getfoodistan() .setFoodistanEndTime(Long.parseLong(temp[0]) * 60000l + System.currentTimeMillis()); // System.out.println(s+"heelo"); } } } catch (NumberFormatException e) { System.out.println(" please check the imput format"); System.exit(1); } if (fdistan.getFoodies().size() == 0 || fdistan.getChefs().size() == 0) { System.out.println(" Either chef or foodies not present"); System.exit(1); } SalesCounter s1 = new SalesCounter(1); fdistan.salesCounters.add(s1); int j; for (j = 0; j < fdistan.getChefs().size(); j++) { fdistan.chefs.get(j).cookItem(ItemType.BURGER); } int f = 0; for (f = 0; f < fdistan.getFoodies().size(); f++) { fdistan.setAvgDiscount( fdistan.getAvgDiscount() + fdistan.getFoodies().get(f).getFoodieDiscount()); } fdistan.setAvgDiscount((int) (fdistan.getAvgDiscount() / fdistan.getFoodies().size())); if (fdistan.getAvgDiscount() > 50 && fdistan.getAvgDiscount() < 70) { fdistan.setSpeedFactor(75); } else if (fdistan.getAvgDiscount() > 70) { fdistan.setSpeedFactor(95); } ThreadA ta = new ThreadA(); ThreadB tb = new ThreadB(); ThreadC tc = new ThreadC(); ThreadD td = new ThreadD(); ThreadE te = new ThreadE(); ThreadF tf = new ThreadF(); ThreadG tg = new ThreadG(); ThreadN tn = new ThreadN(); ThreadO to = new ThreadO(); ThreadK tk = new ThreadK(); // Thread 1 - to order to.start(); ta.start(); tb.start(); tc.start(); td.start(); te.start(); tf.start(); tg.start(); tn.start(); tk.start(); }