Lab 07: 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 developing a "checkout simulation" program to analyze the impact of increasing or decreasing the number of cashiers.
AI Assistance ✨
As usual, do not use AI tools to generate code solutions. However, you are encouraged to use them as a reference for syntax and method usage. But remember, you won't be able to use AI tools during exams, so make sure you understand the concepts and remember the key syntax!
We recommend using Microsoft Copilot Chat (free for all JMU students). You are free to use other AI tools if you prefer.
Getting Started¶
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
Limited Aisle¶
At Bob’s Grocery Mart, customer satisfaction is a top priority. One major factor that affects the shopping experience is wait time at checkout. In real life, customers aren’t willing to wait in extremely long lines, so if a line is too long, they may leave the store without buying anything.
To reflect this behavior in your simulation, you must ensure that customers refuse to enter a checkout line if that line has reached its maximum length.
Instructions¶
-
Create a new class named
LimitedAislethat 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.
AI: Quick Reference ✨
AI tools can be used to quickly refresh your memory on concept like Java's method overriding. You might ask:
"What does it mean to override a method in Java?""What is the difference between overriding and overloading?"
Use these tools to refresh concepts or remind yourself of rules and syntax, but don’t rely on them to write complete programs.
For detailed explanations, online references like Oracle Docs and w3schools Method Overriding are great resources.
-
Modify the
MartSimulationclass so that it uses your newLimitedAislesubclass.- On Line 45:
aisles[i] = new Aisle(generator);replaceAislewithLimitedAisle. You should see a compiler error until completing the next instructions. - Modify the
MartSimulationconstructor to have an additional parameteraisleLengththat specifies how long eachLimitedAislewill be. Use this value as the second argument when creating instances ofLimitedAislein theMartSimulatonconstructor.
- On Line 45:
-
Modify
MartSimulationso 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
Aisleclass does not know about this getter method! In order to call the getter method, you will first need to cast theAisleto 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
MartDriverto give theMartSimulationa 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
MartDriverto 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.