ICS 211 Homework H08: 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.h08

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

2. In package edu.ics211.h08 create the Queue211 interface and Shopper class

Create a new Interface named Queue211, then paste in the contents of Queue211.

The Queue211 interface has the following methods.

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.
}

We will be using the Shopper class to simulate checkout lanes, so create the shopper class.

3. Create a CircularArrayQueue class that implements the Queue211 interface

Create a CircularArrayQueue class that implements the Queue211 interface using a circular array to hold the items in the queue.

All the methods should run in Big O(1). Your CircularArrayQueue class must pass CircularArrayQueueTest. You may want to write additional tests for your CircularArrayQueue.

4. Create a CheckoutLanes class that implements the ICheckoutLanes interface

Create a CheckoutLanes class that has some express lines and regular lines. The class should look something like:

public class CheckoutLanes implements ICheckoutLanes {
  ...
  public CheckoutLanes(int numExpress, int numRegular) { ... }
  public void enterLane(int laneNumber, Shopper shopper) { ... }
  public List<Shopper> simulateCheckout() { ... }
  ...
}

The constructor should create a CircularArrayQueues<Shopper>s for each express and regular lane. Store the queues in one or two arrays. 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 List<Shopper> simulateCheckout() method should loop until all checkout lanes are empty.

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. We create a store with 1 express lane and 2 regular lanes. We add a shopper with 15 items to the express lane, a shopper with 3 items to the express lane, a shopper with 20 items to the first regular lane and a shopper with 17 items to the second regular lane.

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

Since the first shopper in the express lane had too many items they are moved to the back of a regular lane. In this case we choose the first regular lane.

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 H08.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 H08.zip file accept the honor pledge to submit the assignment.