CSC220 Lab Number 5
Due: 10:59AM, Tuesday, October 5
This lab consists of two parts.
Part 1
Download the following file:
The task is to implement missing methods in ListQueue.java.
They are:
- public boolean add(E item)
This is a method required by the AbstractQueue interface.
The method is supposed add the item in the queue and
returns whether the insertion has been successfully done.
- public E remove()
This is a method required by the AbstractQueue interface.
- public E element()
This is also required by the AbstractQueue interface.
-
public int size()
This method is supposed to return the size of the queue.
-
public boolean isEmpty()
This method is supposed to return whether the queue is empty.
-
public Iterator < E > iterator()
This is an iterator method. The Iterator object should be
created as in the KWLinkedList from Lab 3. The class
must implement hasNext() and next() methods. As to remove(),
you may throw UnsupportedOperationException.
Part 2
We want to simulate how customers
are processed at a supermarket. Our eventual goal is to develop a program
for simulation. The simulation is intended to use to classes:
-
The former is a class of a customer. A Customer object has two
data fields, an integer strategy that represents the strategy
of picking a casher and an integer value quantity that represents
the number of items purchased. To create a Customer object you specify
the value for each of the two. The class comes with a static method
called randomCustomer() which randomly decides whether to create
a new customer object, and if it chooses to do so, creates one
with a randomly selected strategy and a randomly selected quantity.
If it chooses not to create one, it returns null.
The random-creation method chooses the strategy from three possibilities
(MAX_STRAT) and the quantity between 1 and MAX_QUANTITY,
which is set to 50. The chances that the method creates a new customer
is ARRIVAL_RATE percent.
A Customer object comes with a method called processOne(),
which decreases the quantity by one and returns true if the quantity
after decreasing reaches 0 and false otherwise.
The three strategies are as follows:
-
STRAT_MIN_TOTAL_ITEMS: This is the strategy in which the customer
chooses a casher that currently has the smallest number of total items
to process.
-
STRAT_MIN_QUEUE_SIZE: This is the strategy in which the customer
chooses a casher that currently has the smallest number of customers
in the queue.
-
STRAT_MIN_TOTAL_ITEMS: This is the strategy in which the customer
chooses a casher randomly.
-
The latter class is a class for a casher.
A Casher has a queue of customers.
The detail of the interface is provided in the interface.
Your task is to implement this interface.