E14: Jamba Juice 3: Implement stock and a store

In Jamba Juice 1 and 2, you implemented code for menus, menu items, and orders. That code implies that a Jamba Juice store has an infinite amount of fruit. Let’s fix that in this WOD.

You will create a class called Inventory that holds the number of available servings of each ingredient at the current time in a Jamba Juice store. So, a store might have an inventory of 50 servings of apple, 73 servings of mango, etc. You’ll create a Store that can specify the current Inventory associated with every ingredient.

Each time a store makes a drink, it has to decrease its inventory of each ingredient by one serving. At some point, the store will run out of a particular ingredient and then it will no longer be able to make any drinks that require it.

Ready? Let’s begin:

  1. Start your timer.

  2. Create a fork of your Jamba Juice 2 JSFiddle to contain the following enhancements.

  3. Create a class called Inventory that holds the number of servings available for each ingredient in a Jamba Juice drink. Provide two methods:

    • setInventory(ingredient, servings). Set the number of servings (integer) associated with the passed ingredient (string)
    • haveServing(ingredient). If the inventory for ingredient is greater than 0, then return true and decrease the inventory for that ingredient by 1. If there is no inventory for that ingredient, return false.
  4. Create an instance of the Inventory class, and set the inventory for a few of the ingredients in our menu items.

  5. Create a class called Store. A store is constructed with an Inventory instance which determines whether or not it has sufficient ingredients to make the Drink. Create a placeOrder(order) method that accepts an Order instance and attempts to fulfill it. It will return an array of all the drink instances it was able to make without running out of ingredients.

  6. Press the “Update” button to create a URL to refer to your code.

  7. Stop your timer and record your time. Be sure to record it, because you will need your WOD time data when you write your technical essay.

Rx: < 18 min Av: 18 - 28 min Sd: 28-35 min DNF: 35+ min


Once you’ve finished trying the WOD for the first time, watch me do it:

Standard WOD Caveats

You’ll learn significantly less from watching me solve the WOD if you haven’t attempted the WOD yourself first.

While it’s an achievement to finish the WOD no matter how long it takes, you might experience “diminishing returns” if you work longer than the DNF time. Thus, it is usually strategic to stop working at the DNF time and watch my solution.

After watching my solution, I recommend that you repeat the WOD if you have not achieved at least Av performance. If so, be sure to:

Feel free to keep trying until you make Rx if that’s of interest to you.

Submission Instructions

By the time and date indicated on the Schedule page, submit this assignment via Laulima.

Your submission should contain:

You will receive full credit for this practice WOD as long as you have attempted it at least once and submitted the email with all required data before the due date. Your code does not have to run perfectly for you to receive full credit. However, if you do not repeat each practice WOD until you can finish it successfully in at least AV time, you are unlikely to do well on the in-class WOD. To reduce the stress associated with this course, I recommend that you repeat each practice WOD as many times as necessary to achieve at least AV before its due date.