ICS 211 Homework A06: Write a simulator of the checkout lines at a store like Foodland.

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.
}
public class CheckoutLanes {
  ...
  public CheckoutLanes(int numExpress, int numRegular) { ... }
  public void enterLane(int laneNumber, Shopper shopper) { ... }
  public void simulateCheckout() { ... }
  ...
}

Testing

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.

Turning in the Assignment

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.

  1. Conduct a personal review of your code before turning it in. Does you code follow the Java Coding Standard? Is it clear and well commented?
  2. Test your code.
  3. Sign into Laulima, then navigate to the ICS211 site. In the left hand side of the site, there is an Assignments tab/link. Click on it and view all of the posted assignments. Select the assignment that you want to turn in and attach your files and accept the honor pledge to submit the assignment.