Question: I am confused about my current project. It is about the array. The capacity of it is fixed, and we need to put the new

I am confused about my current project. It is about the array. The capacity of it is fixed, and we need to put the new items into it. If the current number of items larger than the capacity, for example, the capacity is 5, and the current array is [1,2,3,4,5], we want to put new item 6. The array should change to [2,3,4,5,6]. I complete the toString part.

However, my code print nothing.

I am confused about my current project. It is about the array.

Here is my insert part.

The capacity of it is fixed, and we need to put the

It is the test:

new items into it. If the current number of items larger than

My result:

the capacity, for example, the capacity is 5, and the current array

Another test:

is [1,2,3,4,5], we want to put new item 6. The array should

change to [2,3,4,5,6]. I complete the toString part. However, my code print

3 import java.util.Iterator; 4 5 public class Bag implements LoopBag 6 7 the capacity of bag private int capacity, private EL 1tems; private int n; // number of elements in bag 10 12e 13 14 15 16e 17 18 19 20 21 22e 23 24 25 26 27 28 29 30 31 32 *@param capacity Fixed size bag capacity public Bag(int capacity)i this.capacitycapacity; this. items = CEDnew 0bject [capacity]'; @Override public String toStringO String str- ""; for(int i - 0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!