コード例 #1
0
  public void run() {
    Foodistan fdistan = Foodistan.getfoodistan();
    long waitTime = 0l;
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      for (int x = 0; x < fdistan.getFoodies().size(); x++) {
        Foodie f = fdistan.getFoodies().get(x);
        if (f.getfStatus() == foodieStatus.WAITING) {

          if ((fdistan.getMg().hasInventory(Foodistan.getfoodistan().getInv(), 1) == false)
              || (fdistan.getMg().calculateDiscount() < f.getFoodieDiscount())) {
          } else {
            waitTime = System.currentTimeMillis() - f.getWaitStartTime();
            if (waitTime > fdistan.getMaxWaitingTime()) fdistan.setMaxWaitingTime(waitTime);
            fdistan.setAvgWaitingTime(fdistan.getAvgWaitingTime() + waitTime);
            Item itm = fdistan.getMg().getItem(fdistan.getInv());
            fdistan.getFoodies().get(x).consumeItem(itm);
            fdistan.setAvgItemLifeTime(
                fdistan.getAvgItemLifeTime()
                    + (System.currentTimeMillis() - itm.getItemStartTime()));
            fdistan.getOdrsOnHold().remove(0).setOrdrStatus(orderStatus.COMPLETE);
            fdistan.getFoodiesOnHold().remove(0);
            fdistan.setBurgerNeeded(fdistan.getBurgerNeeded() - 1);
            fdistan.setOrdersDelivered(Foodistan.getfoodistan().getOrdersDelivered() + 1);
          }
        }
      }
    }
  }
コード例 #2
0
  public void run() {
    Foodistan fdistan = Foodistan.getfoodistan();
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      for (int z = 0; z < fdistan.getFoodies().size(); z++) {
        Foodie f = fdistan.foodies.get(z);
        if (f.getfStatus() == foodieStatus.WAITING) {
          /*	if((f.getMaxWaitTime() + f.getWaitStartTime()) - System.currentTimeMillis() < 10000l)
          {
          	if(fdistan.getMg().hasInventory(fdistan.getInv(), 1)){
          		fdistan.setAvgWaitingTime(fdistan.getAvgWaitingTime()+(System.currentTimeMillis()-f.getWaitStartTime()));
          		fdistan.getFoodies().get(z).consumeItem(fdistan.getMg().getItem(fdistan.getInv(), 1));
          		fdistan.getOdrsOnHold().remove(0).setOrdrStatus(orderStatus.COMPLETE);
          		fdistan.getFoodiesOnHold().remove(0);
          		fdistan.setBurgerNeeded(fdistan.getBurgerNeeded()-1);
          		fdistan.setOrdersDelivered(Foodistan.getfoodistan().getOrdersDelivered()+1);

          	}

          }*/
          if ((f.getMaxWaitTime() + f.getWaitStartTime()) < System.currentTimeMillis()) {
            fdistan.foodies.get(z).setfStatus(foodieStatus.DEAD);
            fdistan.getFoodiesOnHold().remove(0);
            fdistan.getOdrsOnHold().remove(0);
            fdistan.setBurgerNeeded(fdistan.getBurgerNeeded() - 1);
            fdistan.setAvgWaitingTime(fdistan.getAvgWaitingTime() + (f.getMaxWaitTime()));
            fdistan.setDeathPenalty(fdistan.getDeathPenalty() + 1);
          }
        }
      }
    }
  }
コード例 #3
0
 public void run() {
   Foodistan fdistan = Foodistan.getfoodistan();
   while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
     for (int n = 0; n < fdistan.getFoodies().size(); n++) {
       Foodie f = fdistan.foodies.get(n);
       if ((f.getfStatus() == foodieStatus.EATING)
           && (f.getEatStartTime() + f.getEatTime() < System.currentTimeMillis())) {
         f.setfStatus(foodieStatus.HUNGRY);
       }
     }
   }
 }
コード例 #4
0
 public void run() {
   Foodistan fdistan = Foodistan.getfoodistan();
   while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
     for (int m = 0; m < fdistan.getFoodies().size(); m++) {
       Foodie f = fdistan.foodies.get(m);
       if (f.getfStatus() == foodieStatus.HUNGRY) {
         Item item =
             f.requestOrder(fdistan.getSalesCounter(), f.getItmTyp(), 1, f.getFoodieDiscount());
         if (item == null) {
           fdistan.foodies.get(m).setWaitStartTime(System.currentTimeMillis());
           fdistan.foodies.get(m).setfStatus(foodieStatus.WAITING);
           Foodistan.getfoodistan().foodiesOnHold.add(f);
         } else f.consumeItem(item);
       }
     }
   }
 }
コード例 #5
0
  /** @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();
  }