public interface Queue211<E> {
boolean add(E e); // adds e to the end of the queue. May throw an IllegalStateException if the queue is full.
E element(); // Retrieves, but doesn't remove the head of the queue. Throws NoSuchElementException if queue is empty.
boolean offer(E e); // adds e to the end of the queue. Returns false if the queue is full.
E peek(); // Retrieves, but doesn't remove the head of the queue. Return null if queue is empty.
E poll(); // Retrieves and removes the head of the queue. Returns null if the queue is empty.
E remove(); // Retrieves and removes the head of the queue. Throws NoSuchElementException if queue is empty.
int size(); // Returns the size of the queue.
}All the methods should run in Big O(1).
Create a Shopper class that has a member variable numItems. Instances of this class represent the shoppers in the store.
Create a CheckoutLanes class that has some express lines and regular lines. The class should look something like:
public class CheckoutLanes {
...
public CheckoutLanes(int numExpress, int numRegular) { ... }
public void enterLane(int laneNumber, Shopper shopper) { ... }
public void simulateCheckout() { ... }
...
}The constructor should create CircularArrayQueues<Shopper>s for the express lanes and the regular lanes. Store the queues in an array. You can use two arrays. There must be at least one regular lane.
The void enterLane(int laneNumber, Shopper shopper) method adds the shopper to the given checkout lane. Express lanes come before regular lanes. If you had 2 express lanes and 4 regular lanes, lanes 0 and 1 are express and 2 - 5 are regular. This method does not check the shopper’s number of items.
The void simulateCheckout() method should loop until all checkout lanes are empty.
Create a test class that instantiates your CheckoutLanes class and adds several shoppers with different number of items. Then run the simulateCheckout method.
Here’s an example:
CheckoutLanes checkout = new CheckoutLanes(1, 2);
checkout.enterLane(0, new Shopper(15));
checkout.enterLane(0, new Shopper(3));
checkout.enterLane(1, new Shopper(20));
checkout.enterLane(2, new Shopper(17));
checkout.simulateCheckout();Could produce the following output:
Express lane shopper with 15 items moved to lane 1
Regular lane 1, shopper had 20 items
Regular lane 2, shopper had 17 items
Express lane 0, shopper had 3 items
Regular lane 1, shopper had 15 itemsPlease thoroughly test your code and briefly discuss your testing strategy. Turn in all test code.
The assignment is due on Friday at 11:55pm. You may turn it in early.