Пример #1
0
  private void processCommand(String command) {
    String[] c = command.split(" ");

    if (c[0].equals("h")) {
      printUsage();
    } else if (c[0].equals("q")) {
      dc.endSession();
      System.exit(0);
    } else if (c[0].equals("w")) {
      showStock(warehouse);
    } else if (c[0].equals("c")) {
      showStock(cart);
    } else if (c[0].equals("p")) {
      try {
        List<SoldItem> soldItems = new ArrayList<SoldItem>();
        for (StockItem stockItem : cart) {
          soldItems.add(new SoldItem(stockItem, stockItem.getQuantity()));
        }
        dc.submitCurrentPurchase(soldItems);
        cart.clear();
      } catch (VerificationFailedException e) {
        log.error(e.getMessage());
      }
    } else if (c[0].equals("r")) {
      try {
        dc.cancelCurrentPurchase();
        cart.clear();
      } catch (VerificationFailedException e) {
        log.error(e.getMessage());
      }
    } else if (c[0].equals("a") && c.length == 3) {
      int idx = Integer.parseInt(c[1]);
      int amount = Integer.parseInt(c[2]);
      StockItem item = getStockItemById(idx);
      item.setQuantity(Math.min(amount, item.getQuantity()));
      cart.add(item);
    }
  }
Пример #2
0
 private void populateWarehouse() {
   warehouse = dc.loadWarehouseState();
 }