The queue in Exercise P15.16 can fill up if more elements are added than the array can hold. Improve the implementation as follows. When the array fills up, allocate a larger array, copy the values to the larger array, and assign it to the elements instance variable. Hint: You can't just copy the elements into the same position of the new array. Move the head element to position 0 instead.

Complete the following file:

CircularArrayQueue.java

Use the following file:

CircularArrayQueueTester.java

/**
   A program to test the CircularArrayQueue class.
*/
public class CircularArrayQueueTester
{
   public static void main(String[] args)
   {
      CircularArrayQueue c = new CircularArrayQueue();
      for (int i = 1; i <= 1000; i++)
         c.add(new Integer(i));

      for (int i = 1; i <= 500; i++)
         c.remove();

      for (int i = 1001; i <= 2000; i++)
         c.add(new Integer(i));

      System.out.println(c.remove());
      System.out.println("Expected: 501");

      for (int i = 1; i <= 1000; i++)
         c.remove();

      System.out.println(c.remove());
      System.out.println("Expected: 1502");
      
      System.out.println(c.size());
      System.out.println("Expected: 498");
   }
}