title: Java cannot find Symbol - containsKey(Item)?
body: <p>In my Supermarket Checkout Program when I run it, it comes up with this error in the <code>Checkout</code> class in the <code>addItem</code> method:</p>
  
  <blockquote>
    <p>cannot find symbol - method containsKey(Item)</p>
  </blockquote>
  
  <p>I cannot understand why it is coming up with this error as I have checked the other two classes (<code>Item</code> and <code>Stock</code>) and I can't see anything wrong with them.</p>
  
  <p>Here are the classes:</p>
  
  <pre><code>import java.text.NumberFormat;
  import java.util.HashMap;
  
  public class Checkout {
      private HashMap&lt;Item, Integer&gt; stock;
  
      /**
       * Constructor for objects of class Checkout. Instantiates the checkout.
       */
      public Checkout() {
          stock = new HashMap&lt;Item, Integer&gt;();
      }
  
  
      public void addItem(String itemCode) {
          Stock stock = new Stock();
          if (stock.containsSalesItem(itemCode)) {
              Item item = stock.getItem(itemCode);
  
              int quantity = 1;
              if (stock.containsKey(item)) {
                  Integer quantity = stock.get(item);
                  quantity += quantity.intValue();
              }
              stock.put(item, new Integer(quantity));
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>import java.text.NumberFormat;
  
  public class Item {
      private String name;
      private String code;
      private int price;
  
      /**
       * Constructor for objects of class Item
       */
      public Item(String itemName, String itemCode, int costOfItem) {
          name = itemName;
          price = costOfItem;
          code = itemCode;
      }
  
      public int getPrice() {
          return price;
      }
  
      public String getName() {
          return name;
      }
  
      public String getCode() {
          return code;
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>import java.util.Map;
  import java.util.HashMap;
  import java.util.Collection;
  
  public class Stock {
      private static Map&lt;String, Item&gt; stock;
  
      static {
          stock = new HashMap&lt;String, Item&gt;();
          stock.put("001", new Item("Diet Coke 1l Bottle", "001", 299));
          stock.put("002", new Item("Haribo", "002", 100));
          stock.put("003", new Item("Digestive Biscuits", "003", 120));
          stock.put("004", new Item("Teacakes", "004", 80));
          stock.put("005", new Item("Bacon", "005", 399));
          stock.put("006", new Item("Bread", "006", 213));
      }
  
      public Collection&lt;Item&gt; getItems() {
          return stock.values();
      }
  
      public Item getItem(String itemCode) {
          return stock.get(itemCode);
      }
  
      public boolean containsSalesItem(String itemCode) {
          if (stock.containsKey(itemCode)) {
              return stock.containsKey(itemCode);
          } else {
              return false;
          }
      }
  } 
  </code></pre>
  
  <p>Thanks for any help and advice.</p>