title: Java Printing Functions
body: <p>I need help writing the printing functions in this java application of another class.</p>
  
  <p>The functions are with printAll I think is right and the other function is definitely wrong.</p>
  
  <pre><code>public void printAll() {
      Iterator&lt;StockItem&gt; iterator = values();
      while (iterator.hasNext())
          System.out.println(iterator.next().toString());
  }
  
  // Prints a directory of all StockItems from the given vendor, 
  // in sorted order (ordered by SKU).
  public void print(String vendor) {
      Iterator&lt;StockItem&gt; iterator = values();
      if (dictionary.getItem(SKU).getVendor() == vendor)
          System.out.println(tmp.toString());
  }
  </code></pre>
  
  <p>The entire function I will write down below for the parts that are needed for this problem.</p>
  
  <pre><code>import data_structures.*;
  import java.util.Iterator;
  
  public class ProductLookup {
  
  
  DictionaryADT&lt;String,StockItem&gt; dictionary;
  private int maxSize;
  
  public ProductLookup(int maxSize, DictionaryADT&lt;String,StockItem&gt; dictionary) {
      this(maxSize);
      this.dictionary = dictionary;
  }
  
  // Constructor.  There is no argument-less constructor, or default size
  public ProductLookup(int maxSize) {
      this.maxSize = maxSize;
  }
  
  // Adds a new StockItem to the dictionary
  public void addItem(String SKU, StockItem item) {
      dictionary.insert(SKU,item);
  }
  
  // Returns the StockItem associated with the given SKU, if it is
  // in the ProductLookup, null if it is not.
  public StockItem getItem(String SKU) {
      if (SKU == null)
          return null;
      return dictionary.getValue(SKU);
  }
  
  // Returns the retail price associated with the given SKU value.
  // -.01 if the item is not in the dictionary
  public float getRetail(String SKU) {
      if (!dictionary.contains(SKU))
          return (float) -.01;
      return getItem(SKU).getRetail();
  }
  
  public float getCost(String SKU) {
      if (!dictionary.contains(SKU))
          return (float) -.01;
      return getItem(SKU).getCost();
  }
  
  // Returns the description of the item, null if not in the dictionary.
  public String getDescription(String SKU) {
      if (!dictionary.contains(SKU))
          return null;
      return getItem(SKU).getDescription();
  }
  
  // Deletes the StockItem associated with the SKU if it is
  // in the ProductLookup.  Returns true if it was found and
  // deleted, otherwise false.  
  public boolean deleteItem(String SKU) {
      if (SKU == null)
          return false;
      return dictionary.remove(SKU);
  }
  
  // Prints a directory of all StockItems with their associated
  // price, in sorted order (ordered by SKU).
  public void printAll() {
      Iterator&lt;StockItem&gt; iterator = values();
      while (iterator.hasNext())
          System.out.println(iterator.next().toString());
  }
  
  // Prints a directory of all StockItems from the given vendor, 
  // in sorted order (ordered by SKU).
  public void print(String vendor) {
      Iterator&lt;StockItem&gt; iterator = values();
      if (dictionary.getItem(SKU).getVendor() == vendor)
          System.out.println(tmp.toString());
  }
  
  // An iterator of the SKU keys.
  public Iterator&lt;String&gt; keys() {
      return dictionary.keys();
  }
  
  // An iterator of the StockItem values.    
  public Iterator&lt;StockItem&gt; values() {
       return dictionary.values();
  }
  }
  </code></pre>
  
  <p>Since it was confusing without actually seeing DictionaryADT I will include it here.</p>
  
  <pre><code>package data_structures;
  
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  
  
  public interface DictionaryADT&lt;K,V&gt; {
  
  // Returns true if the dictionary has an object identified by
  // key in it, otherwise false.
  public boolean contains(K key);
  
  // Adds the given key/value pair to the dictionary.  Returns
  // false if the dictionary is full, or if the key is a duplicate.
  // Returns true if addition succeeded.
  public boolean insert(K key, V value);
  
  // Deletes the key/value pair identified by the key parameter.
  // Returns true if the key/value pair was found and removed,
  // otherwise false.
  public boolean remove(K key);
  
  // Returns the value associated with the parameter key.  Returns
  // null if the key is not found or the dictionary is empty.
  public V getValue(K key);
  
  // Returns the key associated with the parameter value.  Returns
  // null if the value is not found in the dictionary.  If more
  // than one key exists that matches the given value, returns the
  // first one found.
  public K getKey(V value);
  
  // Returns the number of key/value pairs currently stored
  // in the dictionary
  public int size();
  
  // Returns true if the dictionary is at max capacity
  public boolean isFull();
  
  // Returns true if the dictionary is empty
  public boolean isEmpty();
  
  // Returns the Dictionary object to an empty state.
  public void clear();
  
  // Returns an Iterator of the keys in the dictionary, in ascending
  // sorted order.  The iterator must be fail-fast.
  public Iterator&lt;K&gt; keys();
  
  // Returns an Iterator of the values in the dictionary.  The
  // order of the values must match the order of the keys.
  // The iterator must be fail-fast.
  public Iterator&lt;V&gt; values();
  }
  </code></pre>