title: Enhanced for loop not executing
body: <p><strong>UPDATE: Please read the second part of this post that reads "UPDATE". I 've gotten some parts of the code to function since the original post. Thank you!</strong></p>
  
  <p>I have an enhanced for loop in my toString method which returns a string:</p>
  
  <pre><code>public String toString() {
      for (SelectedItem item: cartItems) {
          return "Item: " + item.getItemNumber() + "\nQuantity: " + item.getQuantity + "\nUnit Price: $" + item.getUnitPrice + "\nTotal Price: $" + (item.getUnitPrice * item.getQuantity);
      }
          return "";
  }
  </code></pre>
  
  <p>However, all my code returns is : </p>
  
  <p>"[]</p>
  
  <p>[]". I believe that my code is only executing the return "" part and not the "return 'Item: ...'" section. For reference, here is my full class:</p>
  
  <pre><code>import java.util.*;
  
  public class ShoppingCart implements Cart  {
  
  private double total;
  private double tax;
  private double shipping;
  private int totalQuantity = 0;
  ArrayList&lt;SelectedItem&gt; cartItems = new ArrayList&lt;SelectedItem&gt;();
  
  public ShoppingCart() {
  }
  
  public void addItem(SelectedItem newItem) {     
      for (SelectedItem item: cartItems) {
          if (newItem.getItemNumber() == item.getItemNumber()) {
              totalQuantity = newItem.getQuantity() + totalQuantity;
          } else {
              totalQuantity = newItem.getQuantity();
              cartItems.add(new SelectedItem(newItem.getItemNumber(), newItem.getDescription(), newItem.getUnitPrice(), newItem.getQuantity()));
          }
  
      }
  }
  
  public void deleteItem(int deleteItemNumber) {
  
  }
  
  public double getTotal() {
      return total;
  }
  
  public double getTax() {
      tax = total * 0.045;
      return tax;
  }
  
  public double getShipping() {
      if (total &lt;= 10) {
          shipping = 2.50;
      } else {
          shipping = total * 0.15;
      }
      return shipping;
  }
  
  public String toString() {
      for (SelectedItem item: cartItems) {
          return "Item: " + item.getItemNumber() + "\nQuantity: " + item.getQuantity + "\nUnit Price: $" + item.getUnitPrice + "\nTotal Price: $" + (item.getUnitPrice * item.getQuantity);
      }
          return "";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and here is the <strong>SelectedItem</strong> class:</p>
  
  <pre><code>public class SelectedItem implements Item {
  
  private int itemNumber;
  private String description;
  private double unitPrice;
  private int quantity;
  
  public SelectedItem(int itemNumber, String description,
          double unitPrice, int quantity) {
      this.itemNumber = itemNumber;
      this.description = description;
      this.unitPrice = unitPrice;
      this.quantity = quantity;
  }
  
  public int getItemNumber() {
      return itemNumber;
  }
  
  public double getUnitPrice() {
      return unitPrice;
  }
  
  public String getDescription() {
      return description;
  }
  
  public int getQuantity() {
      return quantity;
  }
  
  public void setQuantity(int newQuantity) {
      quantity = newQuantity;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Lastly, my tester class that is supposed to create instances of the SelectedItem Object:</p>
  
  <pre><code>public class CartTester {
  
  public static void main(String[] args) {
  
      ShoppingCart cart1 = new ShoppingCart();
      cart1.addItem(new SelectedItem(1, "widget", 0.95, 5));
      cart1.addItem(new SelectedItem(2, "gadget", 0.25, 10));
      cart1.addItem(new SelectedItem(3, "doohickey", 0.35, 3));
      cart1.deleteItem(2);
      cart1.addItem(new SelectedItem(3, "doohickey", 0.35, 2));
      cart1.addItem(new SelectedItem(4, "thingamabob", 0.12, 7));
      System.out.println(cart1.toString());
  
      ShoppingCart cart2 = new ShoppingCart();
      for (int i = 1; i &lt;= 1000; i++) {
          String nameString = "Volume " + i;
          cart2.addItem(new SelectedItem(i, nameString, 10.99, i));
      }
      System.out.println("**********");
      System.out.println(cart2.toString());
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Please help me!! Here is the snippet of how the output is supposed to look:</p>
  
  <pre><code>Item: widget
  Quantity: 5
  Unit Price: $0.95
  Total Price: $4.75
  </code></pre>
  
  <p><strong>UPDATE: I've gotten my code to print out the following:</strong></p>
  
  <pre><code>aItem: widget
  Quantity: 5
  Unit Price: $0.95
  Total Price: $4.75
  
  **********
  Item: Volume 1
  Quantity: 1
  Unit Price: $10.99
  Total Price: $10.99
  </code></pre>
  
  <p>.. But it still doesn't print out all the items in ShoppingCart. I've modified my ShoppingCart class and I think the problem is either the AddItem method or toString method. Here is my updated ShoppingCart class:</p>
  
  <pre><code>import java.util.*;
  
  public class ShoppingCart implements Cart  {
  
  private double total;
  private double tax;
  private double shipping;
  private int totalQuantity = 0;
  ArrayList&lt;SelectedItem&gt; compareTo = new ArrayList&lt;SelectedItem&gt;();
  ArrayList&lt;SelectedItem&gt; cartItems = new ArrayList&lt;SelectedItem&gt;();
  String itemDescription = "";
  int itemQuantity;
  double itemUnitPrice;
  double itemTotal;
  
  public ShoppingCart() {
  
      }
  
  public void addItem(SelectedItem newItem) { 
      boolean found = false;
      if (cartItems != null &amp;&amp; !cartItems.isEmpty()) {
         for (SelectedItem item : cartItems) {
             if (newItem.getItemNumber() == item.getItemNumber()) {
                 found = true;
                 item.setQuantity(newItem.getQuantity() + item.getQuantity());
             } 
         }
      } else {
  
      }
      if (found) {
  
      } else {
          cartItems.add(new SelectedItem(newItem.getItemNumber(), newItem.getDescription(), newItem.getUnitPrice(), newItem.getQuantity()));
      }
  
  }
  
  public void deleteItem(int deleteItemNumber) {
      for (SelectedItem item: cartItems) {
          if (deleteItemNumber == item.getItemNumber()) {
              item.setQuantity(0);
          }
      }
  }
  
  public double getTotal() {
      for (SelectedItem item: cartItems) {
          total = item.getQuantity() * item.getUnitPrice();
      }
      return total;
  }
  
  public double getTax() {
      tax = total * 0.045;
      return tax;
  }
  
  public double getShipping() {
      if (total &lt;= 10) {
          shipping = 2.50;
      } else {
          shipping = total * 0.15;
      }
      return shipping;
  }
  
  public String toString() {
          for (SelectedItem item: cartItems) {
              return ("Item: " + item.getDescription() + "\nQuantity: " + item.getQuantity() + "\nUnit Price: $" 
          + item.getUnitPrice() + "\nTotal Price: $" + (item.getQuantity()*item.getUnitPrice()) + "\n");
          }
              return "\nTotal: $" + getTotal() + "\nTax: $" + getTax() + "\nShipping: $" + getShipping() +
                      "\nGRAND TOTAL: $" + (getTotal() + getTax() + getShipping());
      }
  }
  </code></pre>