Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an array of IntArrayBag objects. The length of the array is 10. Each IntA

ID: 3620246 • Letter: C

Question

Create an array of IntArrayBag objects. The length of the array is 10. Each IntArrayBag will be used to collect items, which are integers ranging from 1 to 99. The capacity of each IntArrayBag , which is the sum of all the integers stored in the bag, is at most 100.

Create an array of integers, say curCapacity, to keep track of the capacity of the intArrayBags. This step is necessary, as we need to make sure that the total capacity of each bag cannot exceed 100 at all times.

To conduct this experiment, you need to make use of the random function from the Math class to generate items, which are integers in the range [1,99].

Let FF (resp. RA) be an array of IntArrayBags of length 10 and curFF (resp. curRA) be an integer array of length 10. We will use this set of data structures to simulate the first fit method (resp. the random method).
After an item (I) has just been generated, we attempt to allocate I to the first bag in FF such that it can accommodate I. We must check the data from the curFF array in this step. Likewise, we also attempt to allocate I to a bag in RA. As we are using a random strategy, we simply pick a number from 0 to 9 at random and assign to the corresponding bag in RA. If the corresponding bag cannot hold the item, you need to assign it to the next available bag. For example, if the random number is 5 and the bag RA[5] does not have the capacity to contain the item, then we will try to allocate the item in the following order: RA[6], Create an array of IntArrayBag objects. The length of the array is 10. Each IntArrayBag will be used to collect items, which are integers ranging from 1 to 99. The capacity of each IntArrayBag , which is the sum of all the integers stored in the bag, is at most 100.

Create an array of integers, say curCapacity, to keep track of the capacity of the intArrayBags. This step is necessary, as we need to make sure that the total capacity of each bag cannot exceed 100 at all times.

To conduct this experiment, you need to make use of the random function from the Math class to generate items, which are integers in the range [1,99].

Let FF (resp. RA) be an array of IntArrayBags of length 10 and curFF (resp. curRA) be an integer array of length 10. We will use this set of data structures to simulate the first fit method (resp. the random method).
After an item (I) has just been generated, we attempt to allocate I to the first bag in FF such that it can accommodate I. We must check the data from the curFF array in this step. Likewise, we also attempt to allocate I to a bag in RA. As we are using a random strategy, we simply pick a number from 0 to 9 at random and assign to the corresponding bag in RA. If the corresponding bag cannot hold the item, you need to assign it to the next available bag. For example, if the random number is 5 and the bag RA[5] does not have the capacity to contain the item, then we will try to allocate the item in the following order: RA[6],

Explanation / Answer

Dear Here is class definition public class IntArrayBag implements Cloneable { private int[ ] data; private int manyItems; /** * Initialize an empty bag with an initial capacity of 10. Note that the **/ public IntArrayBag( ) { final int INITIAL_CAPACITY = 10; manyItems = 0; data = new int[INITIAL_CAPACITY]; } /** * Initialize an empty bag with a specified initial capacity. Note that the * addItem method works efficiently (without needing more * memory) until this capacity is reached. **/ public IntArrayBag(int initialCapacity) { if (initialCapacity < 0) throw new IllegalArgumentException ("The initialCapacity is negative: " + initialCapacity); data = new int[initialCapacity]; manyItems = 0; } /** * Add a new element to this bag. If the new element would take this * bag beyond its current capacity, then the capacity is increased * before adding the new element. **/ public void add(int element) { if (manyItems == data.length) { // Ensure twice as much space as we need. ensureCapacity((manyItems + 1)*2); } data[manyItems] = element; manyItems++; } /** * Add new elements to this bag. If the new elements would take this * bag beyond its current capacity, then the capacity is increased * before adding the new elements. **/ public void addMany(int... elements) { if (manyItems + elements.length > data.length) { // Ensure twice as much space as we need. ensureCapacity((manyItems + elements.length)*2); } System.arraycopy(elements, 0, data, manyItems, elements.length); manyItems += elements.length; } /** * Add the contents of another bag to this bag. **/ public void addAll(IntArrayBag addend) { ensureCapacity(manyItems + addend.manyItems); System.arraycopy(addend.data, 0, data, manyItems, addend.manyItems); manyItems += addend.manyItems; } /** * Generate a copy of this bag. **/ public IntArrayBag clone( ) { // Clone an IntArrayBag object. IntArrayBag answer; try { answer = (IntArrayBag) super.clone( ); } catch (CloneNotSupportedException e) { // This exception should not occur. But if it does, it would probably // indicate a programming error that made super.clone unavailable. // The most common error would be forgetting the "Implements Cloneable" // clause at the start of this class. throw new RuntimeException ("This class does not implement Cloneable"); } answer.data = data.clone( ); return answer; } /** * Accessor method to count the number of occurrences of a particular element * in this bag. **/ public int countOccurrences(int target) { int answer; int index; answer = 0; for (index = 0; index
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote