# CSA: Unit 8 Lessonn 7 Exercise 6(a)

**URL:** <https://forum.code.org/t/csa-unit-8-lessonn-7-exercise-6-a/39220>\
**Category:** Coding and Debugging Help\
**Created:** [March 27, 2024, 8:55pm UTC](https://forum.code.org/t/csa-unit-8-lessonn-7-exercise-6-a/39220 "2024-03-27T20:55:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bavarians](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bavarians](https://forum.code.org/u/bavarians)\
**Post date:** [March 27, 2024, 8:55pm UTC](https://forum.code.org/t/csa-unit-8-lessonn-7-exercise-6-a/39220/1 "2024-03-27T20:55:40Z")

</div>

This is my solution to the problem, but when I test it I get an IndexOutOfBounds Exception. I compared it to the teacher’s solution and it seems that the only difference is that in my solution I traverse backwards. Can someone tell me where I’ve gone wrong?

public static void combineSales(ArrayList combined)  
{  
/\* ----------------------------------- TO DO -----------------------------------  
\* ✅ Find duplicate products and combine their total quantities sold. Remove  
\* the duplicate products from the combined list.  
\* -----------------------------------------------------------------------------  
\*/

```
  for(int o = combined.size() - 1; o > -1; o--)
  {
    for(int c = o-1; c > -1; c--)
    {
        Product p = combined.get(o);
        Product p2 = combined.get(c);
        if(p.equals(p2))     
        {
          p.setQuantity(p.getQuantity() + p2.getQuantity());
          combined.remove(c);
        }
    }
  }

```

}

---

<div class="post-metadata">

**Author:** ![sam\_stafford](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/sam_stafford/32/7651_2.png) [@sam\_stafford](https://forum.code.org/u/sam_stafford)\
**Post date:** [March 28, 2024, 3:07am UTC](https://forum.code.org/t/csa-unit-8-lessonn-7-exercise-6-a/39220/2 "2024-03-28T03:07:02Z")

</div>

Hi @bavarians! Thank you for posting your question to the forum.

I copied and pasted your code the method combineSales() and the teacher solution code for combineWeeks() and I am not generating and indexOutOfBounds exception. This leads me to believe that the problem is not with your combineSales() method.

Could you share the link to this level so I can look at it further?

Best  
-Sam
