ICS 211 Homework H07: Simulate checkout lanes at a store like Foodland.

Purpose

Our third abstract data structure is the Queue. For this homework assignment we are going to implement a circular array queue and use it to simulate checkout lines in a store. This assignment should give you more practice with Eclipse and using a queue to store data.

Tasks

1. Create a package named edu.ics211.h07

This is where we will put all our classes for homework 07.

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 List<Shopper> simulateCheckout() { ... }
  ...
}

Testing

You can start with CheckoutLanesTest to 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.

Grading Rubric

CriterionExcellent (100%)Satisfactory (75%)Borderline (50%)Unsatisfactory (25%)Poor (0)
Adherence to standards - 2 points
Does it conform to standards in every detail?
No errors. Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. Misses the point of the assignment.
Breakdown (modular design) - 1 point
Does it demonstrate good modular design?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.
Correctness of code - 4 points
Does it work? Does it pass JUnit?
Passes all tests. Works for typical input, may fail for minor special cases. Fails for typical input, for a minor reason. Fails for typical input, for a major reason. No.
Documentation, and style - 2 points
Is it clear and maintainable? Does it pass CheckStyle?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.
Efficiency of code - 1 point
Does it use the Java features well?
No errors. 1-3 minor errors. > 3 minor errors OR 1 major error. 2 major errors > 2 major error.

Turning in the Assignment

The assignment is due on Friday at 11:55pm. You may turn it in early.

  1. Does your code follow the Java Coding Standard and pass CheckStyle?
  2. Does your code pass the JUnit Tests?
  3. Export your project following the instructions at the bottom of the page. Name the file H07.zip
  4. 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 H07.zip file accept the honor pledge to submit the assignment.