This lab will consist of two parts. The first part focuses on implementing a node-based queue. The second part uses your queue to simulate the checkout lines at a store.
To begin this lab, you should read these lecture slides to learn what a queue is. You should also review your notes and lecture material for information about linked lists.
lab.util
lab.util
.
Their APIs can be found here.Queue
class:
Node
class to implement
the linked sequence. All of the required fields are already provided
for you in the starter code.
enqueue
method should add a new element to the back
of the queue, increasing the size of queue by one. It does so by adding a
new node to the end of the sequence
of nodes. Note that there are two cases that you must handle: (1) the queue
is not empty before you enqueue the element, and (2) the queue is empty
before you enqueue the element.
dequeue
method should remove and return the element
at the front of the queue, decreasing the size of the queue by one.
It does so by removing the node at the front of the sequence of nodes.
peek
method should return the element
at the front of the queue without removing it.
It does so by returning the element stored in the node at the front of the
sequence of nodes.
size
method should return the size of the queue.
isEmpty
method should return true if the queue is
empty and false otherwise.
In this part of the lab you will create a class to simulate a checkout
line. A CheckoutLine
models a queue of customers in a
simulation environment. A Cashier
is a subclass of
CheckoutLine
that models the processing of customers
through the checkout process.
There are many different strategies for managing queues of customers. The most common strategy is to have multiple checkout lines where the customers are free to choose which line to queue in. An alternate strategy is to have a single line for customers to queue in, and the customer at the front of the line is served by the first available cashier.
A simulation of these two strategies can be seen by running the following command from any computer in the Prism lab:
java -jar /cse/dept/www/course/classpath/1030/CheckoutSimulation.jar
The simulation generates customers that arrive at the checkout line(s) after random intervals of time, and each customer requires a random amount of cashier time to process their order. Each time you run the simulation, a new set of 100 customers is generated and passed through the checkout line(s). The amount of time needed to serve all of the customers is printed to the terminal. Which strategy seems to produce the shortest overall checkout time?
To reproduce this simulation, you need to:
Customer
and CheckoutLine
APIs
found here.
CheckoutLine
class. Starter code that
you should use is available here.
submit 1030 lab9 group.txt lab/util/Queue.javaIf something fails, you may see something like
submitted: group.txt (17 bytes) submitted: Queue.java (5934 bytes) All files successfully submitted. Note: lab/util/Queue.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Your Queue class compiled successfully. queue size should be 1 expected:<1> but was:<0> java.lang.AssertionError: queue size should be 1 expected:<1> but was:<0> SUBMITTED FILE Queue.java HAS BEEN REMOVED. PLEASE SUBMIT AGAIN.Fix your code and submit again. If you successfully submitted your code, you will see something like this
submitted: group.txt (17 bytes) submitted: Queue.java (5929 bytes) All files successfully submitted. Note: lab/util/Queue.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Your Queue class compiled successfully. Your Queue class passed all the tests. Your code contains no style errors. Your group.txt file has been successfully validated.
submit -l 1030 lab9After submitting your classes, you should see something like this
The following files have been submitted: group.txt.submitted 17 bytes Queue.java.submitted 5929 bytes CheckoutLine.java.submitted 3715 bytes