Lab 7: Bob's LimitedAisle¶
Bob's Grocery Mart (not real) has 73 locations distributed across 12 States. Bob would like to increase the profitability of his stores by improving cashier scheduling. If too few cashiers are scheduled, customers become frustrated and may not return to the store. But with too many cashiers, Bob pays more wages than necessary.
You have been tasked with extending a checkout simulation program designed to analyze the impact of increasing or decreasing the number of cashiers.
Provided Files¶
Create a lab07
folder in cs159/labs
and download the following files into it:
- Aisle.java (do not edit)
- Customer.java (do not edit)
- MartSimulation.java
- MartDriver.java
Take a few minutes to look over the existing classes to get a feel for how they work. Try executing MartDriver several times to see what the output looks like:
- What is the average wait time with 12 cashiers? minutes
- What is the average wait time with 6 cashiers? minutes
Extending Aisle¶
The simulator for Bob's Grocery Mart has been a great success! Cashiers are being scheduled more efficiently, and profits are up. However, Bob is concerned that some important factors are not captured by the current program. In particular, the simulation allows checkout lines to grow arbitrarily long. Beyond a certain length, real customers would choose to leave the store rather than waiting.
Your goal for this lab is to modify the simulation so that customers will refuse to enter a checkout line if that line has reached some maximum length.
Instructions¶
-
Create a new class named
LimitedAisle
that extendsAisle
. This class should function the same as its superclass, except it will turn away customers if the line is too long.- You will need to add two instance variables, one to store the maximum length of the line and one to store the number of customers that leave because the line is too long.
- Write getter methods for each of these variables. Call one
getMaxLength()
and the othergetLeftStore()
. - You will need to modify the constructor to have a second parameter that specifies this aisle's maximum length.
- Your class should override the
addCustomer()
method so that new customers are added only if the line is below some maximum length. Here, you should also count the number of customers that refuse to wait because the line is too long.
-
Modify the
MartSimulation
class so that it uses your newLimitedAisle
subclass.- On Line 45:
aisles[i] = new Aisle(generator);
replaceAisle
withLimitedAisle
. You should see a compiler error until completing the next instructions. - Modify the
MartSimulation
constructor to have an additional parameteraisleLength
that specifies how long eachLimitedAisle
will be. Use this value as the second argument when creating instances ofLimitedAisle
in theMartSimulaton
constructor.
- On Line 45:
-
Modify
MartSimulation
so that it reports the total number of customers that left the store because of excessive line lengths.- Add a new method called
getTotalLeft()
that returns an int representing all the customers that left.- You will need a loop to total all customers that left, across all the aisles.
- In this loop, you will need to call the getter method you wrote to get the number of customers that left.
Hint
The
Aisle
class does not know about this getter method! In order to call the getter method, you will first need to cast theAisle
to aLimitedAisle
. - Modify the
printResults()
method to include this number:- Add a new line at the bottom of the existing output.
- The new line should be formatted like this example:
Customers that departed: 5
- Make sure you call your
getTotalLeft()
method.
- Add a new method called
-
Edit
MartDriver
to give theMartSimulation
a maximum aisle length of 10. Run your new simulation using eight cashiers, while keeping the other parameters at their default values.- How many customers departed?
-
Now, modify and run
MartDriver
to answer the following questions:- How many customers depart when the maximum line length is 1?
- When the maximum line length is 5?
- When the maximum line length is 20?
-
Finally, modify the
printLabReport()
method to include your above observations.- You only need to change the numbers and put in int literals – no need to call any methods here, add other text, etc.
Submission¶
Submit LimitedAisle
, MartSimulation
, and MartDriver
to Gradescope.