title: Adding a quantity to multiple indexes in an array (java)
body: <p>So my problem is that I have a vending machine. The vending machine has slots with a max number of items per slot. </p>
  
  <p>If I run the restock method with a product name and quantity, I need to add the quantity to the product supplied. I have a string array, and a stock array, for which the index is the slot number. </p>
  
  <p>The problem is that if I have the same named product twice in the list, the first index of the product will reach the max, but the second instance of the product is always 1 less than I need it to be.</p>
  
  <p>Ex. 
  I have candies at slot 0 and 1 with a max of 10.
  running restock(candies, 8) then restock(candies, 5) should provide 10 in slot 0 and 3 in slot 2. But instead I get 10 and 2. </p>
  
  <pre><code>public void restockProduct(String product, int quantity) {
      int index = -1;
      // If there is nothing to add, quit
      if (quantity == 0) {
          return;
      }
      for (int i = 0; i &lt; products.length; i++) {
          //Find location of product
          if (products[i].equals(product)) {
              index = i;
              if(stock[index] &lt;= max)
              break;
          }
      }
      if(index &gt;=0){
          stock[index]++;
          restockProduct(product, quantity-1);
      }
  </code></pre>
  
  <p>THanks</p>