title: use of synchronized method in affable bean shopping cart
body: <p>having a look at the netbeans affable bean tutorial. Why do we need the use of synchronized methods here?</p>
  
  <pre><code>public synchronized int getNumberOfItems() {
  
          numberOfItems = 0;
  
          for (ShoppingCartItem scItem : items) {
  
              numberOfItems += scItem.getQuantity();
          }
  
          return numberOfItems;
      }
  
  
      public synchronized double getSubtotal() {
  
          double amount = 0;
  
          for (ShoppingCartItem scItem : items) {
  
              Product product = (Product) scItem.getProduct();
              amount += (scItem.getQuantity() * product.getPrice().doubleValue());
          }
  
          return amount;
      }
  </code></pre>