Exemplo n.º 1
0
  public synchronized int getNumberOfItems() {
    numberOfItems = 0;

    for (Iterator i = getItems().iterator(); i.hasNext(); ) {
      ShoppingCartItem item = (ShoppingCartItem) i.next();
      numberOfItems += item.getQuantity();
      System.out.println("number of items is " + numberOfItems);
    }

    return numberOfItems;
  }
Exemplo n.º 2
0
  public synchronized double getTotal() {
    double amount = 0.0;

    for (Iterator i = getItems().iterator(); i.hasNext(); ) {
      ShoppingCartItem item = (ShoppingCartItem) i.next();
      BookDetails bookDetails = (BookDetails) item.getItem();

      amount += (item.getQuantity() * bookDetails.getPrice());
    }

    return roundOff(amount);
  }
Exemplo n.º 3
0
  public synchronized void remove(String bookId) {
    if (items.containsKey(bookId)) {
      ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId);
      scitem.decrementQuantity();

      if (scitem.getQuantity() <= 0) {
        items.remove(bookId);
      }

      numberOfItems--;
    }
  }
Exemplo n.º 4
0
  public synchronized void add(String bookId, BookDetails book) {
    if (items.containsKey(bookId)) {
      ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId);
      scitem.incrementQuantity();
      System.out.println("in add, quantity is " + scitem.getQuantity());
    } else {
      ShoppingCartItem newItem = new ShoppingCartItem(book);
      items.put(bookId, newItem);
      System.out.println("in add, quantity is " + newItem.getQuantity());
    }

    //      numberOfItems++;
  }