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() { ... }
...
}
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 items
Please thoroughly test your code and briefly discuss your testing strategy. Turn in all test code.
The assignment is due on Friday at 11:59pm. You may turn it in early. If you haven’t completed the assignment by 11:58, turn in what you have. Getting partial credit is much better then no credit.