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 08.
Create a new Interface named Queue211, then paste in the contents of Queue211.
The Queue211 interface has the following methods.
We will be using the Shopper class to simulate checkout lanes, so create the shopper class.
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.
Create a CheckoutLanes class that has some express lines and regular lines. The class should look something like:
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.
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.
Could produce the following output:
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.
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.