# CoffeeMaker Requirements - version 2.0

CoffeeMaker is an online beverage ordering system, similar in spirit to GrubHub. The requirements below are written as use cases — a way of modeling requirements from the user's perspective. Each use case describes the preconditions needed to reach it, the main flow of functionality, and alternative/error paths.

After discussing the CoffeeMaker project with others, we had several feature requests. One was the ability to add other types of ingredients beyond coffee, milk, sugar, and chocolate. Customers also want tea, cider, pumpkin spice, and other drinks they might get at a coffee shop.

Version 2.0 updates the requirements to support **arbitrary ingredients**. Text that is new or changed since version 1.0 is shown in **bold**.

## What Changed in Version 2.0

- A new **[UC7 Add Ingredients](#uc7)** lets a user define a new ingredient and its starting inventory.
- Recipes are no longer limited to the four fixed ingredients. [UC2](#uc2) and [UC4](#uc4) let a user add, remove, and set units for any ingredient the system knows about.
- A recipe with no ingredients is now an error in both [UC2](#uc2) and [UC4](#uc4).
- [UC5 Update Inventory](#uc5) applies to every ingredient, not just the original four.
- [UC1 Display Menu](#uc1) gains an Add Ingredient option.

[UC6 Order Beverage](#uc6) is unchanged in wording, but its implementation must work with arbitrary ingredients.

## <a id="uc1"></a>Use Case 1: Display Menu

Display a menu of options for working with the CoffeeMaker system for a user.

### Main Flow

1. A user goes to the CoffeeMaker website.
2. A user selects one of the following menu options:
   - Add Recipe [[UC2]](#uc2)
   - Delete Recipe [[UC3]](#uc3)
   - Edit Recipe [[UC4]](#uc4)
   - Update Inventory [[UC5]](#uc5)
   - Order Beverage [[UC6]](#uc6)
   - **Add Ingredient [[UC7]](#uc7)**

## <a id="uc2"></a>Use Case 2: Add Recipe

**Preconditions:** User selected the Add Recipe option from the menu [[UC1]](#uc1)

### Main Flow

1. A user selects the option to add a recipe.
2. The user enters the name and price of the recipe, and **the units of each ingredient** [[Add Ingredient]](#uc2-s1) [[Remove Ingredient]](#uc2-s3) [[Edit Units]](#uc2-s4) that make up the recipe [[Too Many]](#uc2-a1) [[Invalid Price]](#uc2-a2) [[Invalid Unit]](#uc2-a3) [[Duplicate]](#uc2-a4) [[No Ingredients]](#uc2-a5).
3. The user returns to the main menu [[UC1]](#uc1).

### Subflows

- <a id="uc2-s1"></a>**[Add Ingredient] A user can select a new ingredient to add to the recipe.**
- <a id="uc2-s2"></a>**[Add Ingredient] A user can select two new ingredients to add to the recipe.**
- <a id="uc2-s3"></a>**[Remove Ingredient] A user can remove an ingredient in the recipe.**
- <a id="uc2-s4"></a>**[Edit Units] A user can provide a unit for the ingredient [[Invalid Unit]](#uc2-a3).**

### Alternative Flows

- <a id="uc2-a1"></a>[Too Many] If there are already three recipes in the system, then a new recipe may not be added. An error message is printed, and the recipe is not added.
- <a id="uc2-a2"></a>[Invalid Price] The price must be a positive integer. If the price is not a positive integer, an error message is printed, and the user is returned to the form to edit. The recipe is not added.
- <a id="uc2-a3"></a>[Invalid Unit] The units of an ingredient must be positive integers. If the unit value on any of the ingredients is not a positive integer, an error message is printed, and the user is returned to the form to edit. The recipe is not added.
- <a id="uc2-a4"></a>[Duplicate] If the name of the new recipe already exists in a recipe in the system, an error message is printed, and the user is returned to the form to edit. The recipe is not added.
- <a id="uc2-a5"></a>**[No Ingredients] If the recipe has no ingredients, then an error message is printed, and the user is returned to the form to edit. The recipe is not added.**

## <a id="uc3"></a>Use Case 3: Delete Recipe

**Preconditions:** User selected the Delete Recipe option from the menu [[UC1]](#uc1)

### Main Flow

1. The user will be shown a list of all recipes in the system.
2. The user may select one or more recipes that they want to delete.
3. The user selects the option to delete the recipes.
4. The selected recipes are deleted and a success message is displayed [[Cannot Delete]](#uc3-a1).
5. The user returns to the main menu [[UC1]](#uc1).

### Alternative Flows

- <a id="uc3-a1"></a>[Cannot Delete] If the recipe is deleted by a concurrent user before it is selected for deletion, an error message is printed and the user is returned to the delete recipe page with an updated list of recipes.

## <a id="uc4"></a>Use Case 4: Edit Recipe

**Preconditions:** User selected the Edit Recipe option from the menu [[UC1]](#uc1)

### Main Flow

1. The user will be shown a list of all recipes in the system.
2. The user may select one recipe that they want to edit [[Cannot Edit]](#uc4-a1).
3. After selecting a recipe, the form will be pre-filled with all existing values (price and **units of all ingredients**) for the selected recipe.
4. The user edits the price and **the ingredients** [[Add Ingredient]](#uc4-s1) [[Remove Ingredient]](#uc4-s2) [[Edit Units]](#uc4-s3) that make up the recipe [[Cannot Edit]](#uc4-a1) [[Invalid Price]](#uc4-a2) [[No Ingredients]](#uc4-a4).
5. The user returns to the main menu [[UC1]](#uc1).

### Subflows

- <a id="uc4-s1"></a>**[Add Ingredient] A user can select a new ingredient to add to the recipe.**
- <a id="uc4-s2"></a>**[Remove Ingredient] A user can remove an ingredient in the recipe.**
- <a id="uc4-s3"></a>**[Edit Units] A user can provide a unit for the ingredient [[Invalid Unit]](#uc4-a3).**

### Alternative Flows

- <a id="uc4-a1"></a>[Cannot Edit] If the recipe is deleted by a concurrent user before it is selected for edit, an error message is printed and the user is returned to the edit recipe page with an updated list of recipes.
- <a id="uc4-a2"></a>[Invalid Price] The price must be a positive integer. If the price is not a positive integer, an error message is printed, and the user is returned to the form to edit. The recipe is not changed.
- <a id="uc4-a3"></a>[Invalid Unit] The units of an ingredient must be positive integers. If the unit value on any of the ingredients is not a positive integer, an error message is printed, and the user is returned to the form to edit. The recipe is not changed.
- <a id="uc4-a4"></a>**[No Ingredients] If the recipe has no ingredients, then an error message is printed, and the user is returned to the form to edit. The recipe is not changed.**

## <a id="uc5"></a>Use Case 5: Update Inventory

**Preconditions:** User selected the Update Inventory option from the menu [[UC1]](#uc1)

### Main Flow

1. The user will be shown a listing of the current inventory of ingredients in the CoffeeMaker.
2. The user enters the amount of inventory to add for each ingredient [[Invalid Unit]](#uc5-a1).
3. The current inventory values are updated after inventory is added.
4. The user returns to the main menu [[UC1]](#uc1).

### Alternative Flows

- <a id="uc5-a1"></a>[Invalid Unit] The units of **the ingredients** must be positive integers. If the unit value on any of the ingredients is not an integer, an error message is printed, and the user is returned to the form to edit. No inventory is added.

## <a id="uc6"></a>Use Case 6: Order Beverage

**Preconditions:** User selected the Order Beverage option from the menu [[UC1]](#uc1)

### Main Flow

1. The user will select the beverage they want to purchase.
2. The user enters the amount of money they will use to purchase the beverage.
3. The user requests the beverage.
4. The system will check if there are enough ingredients in the inventory to make the selected beverage [[Insufficient Ingredients]](#uc6-a1).
5. The system will check if there is enough money to pay for the beverage [[Insufficient Payment]](#uc6-a2) [[Invalid Payment]](#uc6-a3).
6. If there are enough ingredients and the money paid is sufficient, the ingredients to make the purchased beverage will be removed from the inventory.
7. A message indicating that the beverage is ready and the user's change will be displayed.
8. The user may return to the main menu [[UC1]](#uc1).

### Alternative Flows

- <a id="uc6-a1"></a>[Insufficient Ingredients] If there is not enough inventory to make the beverage, an error message is printed, the user's money will be returned, and the user will be returned to the purchase beverage page. No inventory is used.
- <a id="uc6-a2"></a>[Insufficient Payment] If the user does not enter enough money, an error message is printed, their money will be returned, and the user will be returned to the purchase beverage page. No inventory is used.
- <a id="uc6-a3"></a>[Invalid Payment] If the payment entered is not numeric or not an integer, an error message is printed, the user's money will be returned (if the input was numeric), and the user will be returned to the purchase beverage page. No inventory is used.

## <a id="uc7"></a>Use Case 7: Add Ingredients

**This use case is new in version 2.0.**

**Preconditions:** User selected the Add Ingredient option from the menu [[UC1]](#uc1)

### Main Flow

1. The user enters a name for the ingredient.
2. The user enters the initial amount of the ingredient in the system inventory.
3. The user clicks add ingredient [[Invalid Unit]](#uc7-a1) [[Duplicate]](#uc7-a2).
4. The user may enter another ingredient or return to the main menu [[UC1]](#uc1).

### Alternative Flows

- <a id="uc7-a1"></a>[Invalid Unit] The units of the ingredient must be positive integers. If the unit value is not an integer, an error message is printed, and the user is returned to the form to edit. No ingredient or inventory is added.
- <a id="uc7-a2"></a>[Duplicate] If the name of the new ingredient already exists in the system, an error message is printed, and the user is returned to the form to edit. No ingredient or inventory is added.
