Beispiel #1
0
  private void output() {
    for (Deal deal : deals) {
      System.out.println("Deal " + deal.getDate());
      System.out.println(
          "    " + deal.getBuyer().getName() + " buys from " + deal.getSeller().getName());

      for (Entry<Product, Integer> entry : deal.getProducts().entrySet()) {
        Product product = entry.getKey();
        int quantity = entry.getValue();
        System.out.println(
            "        "
                + product.getTitle()
                + " "
                + quantity
                + " x "
                + product.getPrice()
                + " = "
                + product.getCost(quantity));
      }

      System.out.println("Sum: " + deal.getSum());
      System.out.println("----------------------------");

      outputParty(deal.getBuyer());
      outputParty(deal.getSeller());
      System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    }
  }
Beispiel #2
0
 public double getSum() {
   double result = 0;
   for (Entry<Product, Integer> entry : products.entrySet()) {
     Product product = entry.getKey();
     int quantity = entry.getValue();
     result += product.getCost(quantity);
   }
   return result;
 }
Beispiel #3
0
  private Product inputProduct() {
    Product product = null;

    String reply = keyboard(" Select product (y - Yes, n - No");
    if (reply.compareToIgnoreCase("y") == 0) {
      product = selectProduct();
    }

    if (product != null) {
      return product;
    }

    String productType = keyboard("    1 - Foto, 2 - Botinki");

    String title = keyboard("    Name");
    String price = keyboard("    Price");

    if (productType.equals("1")) {
      String megapx = keyboard("    Megapixel");
      String digital = keyboard("    True - Digital, False - Non-Digital");

      FotoProduct fotoProduct = new FotoProduct();
      fotoProduct.setDigital(Boolean.valueOf(digital));
      fotoProduct.setMegapx(Double.valueOf(megapx));

      product = fotoProduct;
    } else if (productType.equals("2")) {
      String size = keyboard("    Size");
      String color = keyboard("    Color");

      BotinkiProduct botinkiProduct = new BotinkiProduct();
      botinkiProduct.setSize(Integer.valueOf(size));
      botinkiProduct.setColor(color);

      product = botinkiProduct;
    } else {
      System.err.println("Unknown product");
      System.exit(-1);
    }

    product.setTitle(title);
    product.setPrice(Double.valueOf(price));

    // adds products to cache
    this.products.add(product);

    return product;
  }