예제 #1
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();
  }