Lab 2
Get started now
## Objectives * Translate UML class diagrams into source code * Construct software which uses an interface * Employ aggregation and composition in a software system * Use the `java.util.ArrayList` collection class to hold class data ## Resources * [EvaporatedMilk](EvaporatedMilk.java) * [Kitchen](Kitchen.java) __updated 12/11/19__ [old version](KitchenOld.java) * [cookies](cookies.txt) * [cake](cake.txt) ## Introduction In this lab, you will explore using interfaces to make deserts. By using interfaces, you can treat prepared ingredients the same as the basic (simple) ones. There are three preparation techniques provided in this lab: 1. Baking 2. Measuring 3. Mixing Every ingredient, simple or prepared, provides basic information about itself: * The ingredient's name * The energy content in Calories (kcal) * The volume of the ingredient (cups) * A recipe for preparing the ingredient Preparation techniques use existing ingredients to create new ones. ## Assignment Details A class diagram for the program is shown in the figure below: <figure>[![UML Class Diagram](ingredientUML.png)](ingredientUML.png)</figure> Implement all of the classes shown in the diagram above based on the discussion that follows. The arrows with black diamonds simply indicate that one class has a reference to another. These references are also shown as member variables in the class diagrams for the three prepared ingredients (`Measure`, `BakedIngredient`, and `Mix`) Simple ingredients print a simple recipe listing the name of the ingredients in the title (between two lines of equal signs) and the basic information about the ingredient. For example, the `SimpleIngredient` milk prints this recipe: ``` ==================================================== Milk ==================================================== Cups: 1 Cups Energy: 103 Calories ``` Energy is rounded to the nearest Calorie, and volume is rounded to the hundredth of a Cup. If fractional digits are zero, they are ommited as shown here. A baked ingredient keeps the same number of calories, but becomes dry and increases its volume by a user-provided expansion factor. (The new volume is $ \mathrm{EXPANSION\\_{FACTOR}} \times volume $ where $ volume $ is the volume of the `bakedIngredient`.) A measured ingredient maintains the energy density of the original ingredient, <mark>but measures a different quantity of it. The new quantity becomes part of the ingredient's name</mark>. The new volume is specified as $ numerator / denominator $ cups, where the denominator defaults to 1 if it is not provided. The calories are given by $ numerator / denominator \times energy / volume $ where the $ energy $ and $ volume $ describe the original ingredient. When printing its ingredient list, the measured ingredient lists the quantity both as a fraction and then, in parenthesis, as a decimal number to the nearest hundredth. See the cake output at the end for examples. A mixed ingredient is a combination of several existing ingredients. The volume and energy of the mix are simply the sum of the volume and energy of each of the ingredients in the mix, respectively. (This is a bit of an approximation, especially for volume!) A mix is wet if any of the ingredients is wet. A mixed ingredient's recipe lists the dry and wet ingredients separately, as shown in the `ice cream` example a little later on. Each prepared ingredient (baked, measured, and mixed) prints its own recipe and the recipe for each ingredient it is prepared from. For example, the `dry milk` option of the Kitchen program prints the recipe for baked milk, which in turn prints the recipe for the milk it is baked from: ``` ==================================================== Baked Milk ==================================================== Ingredient to be baked: Milk Cups: 0.2 Cups Energy: 103 Calories ==================================================== Milk ==================================================== Cups: 1 Cups Energy: 103 Calories ``` Similarly, `ice cream` prints first the main recipe, and then the recipe for each ingredient it is made from: ``` ==================================================== Ice Cream ==================================================== Dry Ingredients: Sugar Wet Ingredients: Cream Milk Cups: 2.12 Cups Energy: 980 Calories ==================================================== Cream ==================================================== Cups: 0.12 Cups Energy: 104 Calories ==================================================== Milk ==================================================== Cups: 1 Cups Energy: 103 Calories ==================================================== Sugar ==================================================== Cups: 1 Cups Energy: 773 Calories ``` A prepared ingredient may be used to prepare further ingredients. For example, in the cookie recipe, each ingredient in the mix is itself a measured ingredient: <figure>[![Cookies Hierarchy](cookies.png)](cookies.png)</figure> The final recipe is for a cake. The frosting and batter are prepared separately, and then combined: <figure>[![Cake Hierarchy](cake.png)](cake.png)</figure> You may add new options to the example program, but do not edit the options provided in the example. Let the single `printRecipe()` call print everything. ## Appendix: cookie and cake examples. Here is the output for the two remaining options of [Kitchen.java](Kitchen.java) * [cookies](cookies.txt) * [cake](cake.txt) All of the classes must be in a package with your username. (You will need to modify the package declaration for the `Driver` from `FIXME` to your MSOE username.) ## Acknowledgment This laboratory assignment was developed by [Dr. Josiah Yoder](http://faculty-web.msoe.edu/yoder). <div class="notetip"> See your professor's instructions for details on submission guidelines and due dates. </div>

Thursday, 27-Feb-2020 09:23:27 EST