CSCE 146

Lab 02

Download the class IntArrayBag.java class  

 

  1. Add a new method equals(), which compares two IntArrayBag objects and returns true is they are equal. Two bags are equal if they have the same integers, though not necessarily in the same order. To devise an algorithm for testing for equality, consider using the countOccurrences() method of the IntArrayBag classs to compare how many times a specific integer occurs in both the bags. The test for equality will fail if for any integer in a bag, the number of times it occurs in that bag is different from the number of times it occurs in the other bag.

  2. Write a Test class to test the equals() method that you have written. The class should instantiate 2 bag objects which have the same inetgers and then invoke the equals() method to test for equality between these 2 bags. Similarly, test for equality between 2 bags that have different integers.