This quiz is intended to prepare you for Q3.

Before you start:

Getting started

Create a PQ3 project and import PQ3-starter.jar.

Your directory should look like this:

PQ3/
└── src
    └── PQ3.java
Instructions

Use the javadoc to complete the following methods using a circular array queue:

  1. public PQ3(int capacity) (10 points)

  2. public E[] newArray(int capacity) (10 points)

  3. public E[] removeNItems(int n) (35 points)

  4. public boolean addNItems(E[] items) (35 points)

  5. public int size() (10 points)

Testing

We’ve supplied you with a few test cases in the main method for PQ3 but have not tested corner cases. You will want to make note of what you forgot to test for because we will be doing similar testing for the quiz.

Here is what should be printed when running the main method:

Testing the constructor with a capacity of 10: [null, null, null, null, null, null, null, null, null, null]
Size of queue after operation: 0
Testing the newArray method with a capacity of 5: [null, null, null, null, null]

Trying to add 5 items
Able to add 5 items-> true
Size of queue after operation: 5
Array after adding 5 ints: [1, 2, 3, 4, 5, null, null, null, null, null]

Trying to remove 4 items
Items removed: [1, 2, 3, 4]
Size of queue after operation: 1
Array after trying to remove four items: [null, null, null, null, 5, null, null, null, null, null]

Trying to add 8 items
Able to add 8 items-> true
Size of queue after operation: 9
Array after adding 8 more ints: [6, 7, 8, null, 5, 1, 2, 3, 4, 5]
Submission

Once complete, submit PQ3.java to Checkin for feedback.