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],