This quiz is intended to prepare you for Q3
.
Before you start:
-
Set a timer and try to do the quiz within 40 minutes without asking teachers, friends, or the internet.
-
Once you have tried doing this and figured out the questions, attempt the quiz again. Become comfortable with the code.
Create a PQ3
project and import PQ3-starter.jar.
Your directory should look like this:
PQ3/ └── src └── PQ3.java
Use the javadoc to complete the following methods using a circular array queue:
-
public PQ3(int capacity)
(10 points) -
public E[] newArray(int capacity)
(10 points) -
public E[] removeNItems(int n)
(35 points) -
public boolean addNItems(E[] items)
(35 points) -
public int size()
(10 points)
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]
Once complete, submit PQ3.java
to Checkin
for feedback.