Inheritance Lab

Inheritance in Bob’s Grocery Mart

Introduction

The Bob's Grocery Mart Simulator has been a big 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 assignment is to modify the simulation so that customers will refuse to enter a checkout line if that line has reached some maximum capacity.

Instructions

  • Download the following files:
  • 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?
    • What is the average wait time with 6 cashiers?
  • Create a new class that extends Aisle. As always, you should think carefully about what to name your class. One common convention in naming subclasses is to prefix the superclass name with an adjective the clarifies how the subclass specializes the superclass. For example, the Car class might have a subclass named ElectricCar. We recommended you call your class LimitedAisle.
    • Your new class must:
      1. Override the addCustomer method so that new customers are added only if the line is below some maximum capacity.
      2. Track the number of customers that refuse to wait because the line was too long.
  • Modify the simulation class so that it uses your new LimitedAisle subclass: everywhere “Aisle” appears in the existing class should be replaced with your “LimitedAisle”. You should modify the simulation constructor so that it accepts a “maximum length” parameter that describes maximum allowable length for a checkout line.
  • Modify the printResults method so that it reports the total number of customers that left the store because of excessive line lengths.
  • Test your new simulation using eight aisles, while keeping the other parameters at their default values. How many customers depart when maximum line length is 1? 5?, 20? (INCLUDE AN ANSWER TO THIS QUESTION IN A COMMENT AT THE BOTTOM OF YOUR NEW CLASS. )
  • Submit your completed LimitedAisle subclass and modified MartSimulation in Gradescope. It is your responsibility to make sure that the behavior is correct as the submission only checks if your code compiles. If you aren’t sure, check with your instructor or a TA.
  • If you have extra time:
    • Each time this simulation is executed, there is a different result. It might be valuable to know the average results across many different simulation runs. Add a new method to the MartSimulation class with the signature:
      public void runMany(int numRuns)
      
      This method should run the simulation the indicated number of times, and calculate averages for each of the quantities reported.

  • If you have even more time:

    It would be useful to be able to systematically adjust simulation parameters in small increments to see what effect this has on wait times etc. Add a loop to your main that systematically increases the maximum line length from 0 to 100. For each increment, run your simulation 100 times and report the average results.

Last modified May 1, 2023: student-sourced updates (1f18b77)