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.
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() { ... }
...
}Use the Shopper class that has a member variable numItems. Instances of this class represent the shoppers in the store.
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 List<Shopper> simulateCheckout() method should loop until all checkout lanes are empty.
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 itemsPlease thoroughly test your code and briefly discuss your testing strategy. Turn in all test code.
| Criterion | Excellent (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. |
The assignment is due on Friday at 11:55pm. You may turn it in early.