Create a new class that extends Aisle. Your new class should override
the addCustomer
method so that every time a new customer
is added, the entire list of customers is sorted. This way, the
customer with the fewest items is always moved to the front. This
type of aisle will model the effect of friendly customers that let
other customers "cut" if they have fewer items.
You should use the Collections.sort method to sort
your ArrayList. Since this method only works when the items in the
list implement the Comparable interface, you will also
need to modify the Customer
class to
implement Comparable
.
Comparable
is a generic interface. This means you can use it like this:
public class MyClass implements Comparable<MyClass>or like this:
public class MyClass implements ComparableIn the former class your compareTo method must take an argument of type
MyClass
in the latter it must take an argument of type Object
SortedAisle
class modify
MartSimulation so that it uses SortedAisle
s instead
of LimitedAisle
s, and confirm that your code works
correctly. Using SortedAisle
should result in relatively
short average waits, but very long longest waits. People with lots of
items will tend to get stuck at the end of the line while others
continually cut in front of them.
It is unfortunate that the current version of the simulation requires
the code to be modified and recompiled when we want to change the
aisle type used in the simulation. Modify the
file MartDriver
and MartSimulation
classes
to allow the user to select any of the three aisle types at run time.
Execute the simulation several times to see the effect of changing aisle
types.
Submit all of your .java files through Canvas.