CS1021
Software Development II
In Lab 3 (we are doing Lab 3 earlier than the other sections), we will explore using interfaces to make deserts. By using interfaces, we can treat prepared ingredients the same as the basic (simple) ones. ## Lab 2 Milestone The provided <a href="lab3res/EvaporatedMilk.java">EvaporatedMilk</a> produces evaporated milk from milk. You will implement it during our Week 2 Lab Period To implement it you will need to implement the Ingredient interface, the SimpleIngredient class, and the BakedIngredient class. The baked ingredient class has an instance variable representing the object being baked. When baked, an object keeps the same number of calories, <strike>but grows 20% in volume and becomes dry. (True, evaporated milk should actually shrink.. this will make more sense for cakes...</strike> <mark>but becomes dry and shrinks to 20% of its original volume (the volume is multiplied by the provided EXPANSION_FACTOR).</mark> <p>You do not need to write any of the other clases for the milestone.</p> <center><a href="lab3res/class.png" width="700"><img src="lab3res/class.png" /></a></center> <p><mark>When any of the Ingredient classes print its recipe, it first prints a header containing its name between two lines of equal signs.</mark></p> ## Objectives * Translate UML class diagrams into source code * Construct software using an interface * Employ aggregation and composition in the development of software ## Assignment In this lab, we will explore using interfaces to make deserts. By using interfaces, we can treat prepared ingredients the same as the basic (simple) ones. There are three preparation techniques provided in this lab: (1) baking (2) measuring and (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 * 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](lab3res/class.png)](lab3res/class.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](lab3res/cookies.png)](lab3res/cookies.png)</figure> The final recipe is for a cake. The frosting and batter are prepared separately, and then combined: <figure>[![Cake Hierarchy](lab3res/cake.png)](lab3res/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](lab3res/Kitchen.java) * [cookies](lab3res/cookies.txt) * [cake](lab3res/cake.txt) ## Submission Instructions for Dr. Yoder Please submit the lab through [esubmit](http://esubmit.msoe.edu). See [Lab 1](Lab1) for instructions for accessing esubmit from off-campus. <p class="beforeList"><mark>You will upload:</mark></p> <ul> <li>Your individual .java<!-- and .fxml--> files<br> &mdash;and&mdash; <!--<li>An executable .jar file--> <li>A README.md file with an informal report (see below) </ul> <mark>Code should follow the <a href="http://msoe.us/taylor/cs1021/CodingStandard">Coding Standard</a>.</mark> <br /> <p><mark>If you are submiting a draft submission to esubmit (especially near or after the deadline), please include the empty file DONOTGRADE.txt (in big bold capital letters, just like that!) so that I don't start grading something until you intend it to be complete. You can continue making submissions which will be counted as on-time until the deadline or a few minutes after.</mark></p> <p class="beforeList"><mark>Please use the template below for your README.md file. If you create the file from within IntelliJ by right-clicking on your source folder and selecting "new-&gt;file", you can just type in README.md, and it will even interpret the markdown for you!</mark></p> <pre> ## Introduction [Replace this line with a description of the lab in your own words] ## Conclusion [Replace this line with a description of what you learned in this lab] ## Things I Liked / Suggestions for Improvement [Replace this line with what you liked or think could be improved about the lab. (Required.)] </pre> Esubmit will run your code and check your output against the examples given in the lab. Although your output does not need to exactly match the output on esubmit, please make it close and consider whether differences are relavent. For example, a different number of equal signs on the lines does not matter, but making things singular that should be plural and vice-versa could. Exercise your own discression in evaluating these differences. If you see any of the following errors, please resubmit your lab. (You may submit multiple times before the deadline.) If you see this: <figure>[![File not found](lab3res/fileNotFound.png)](lab3res/fileNotFound.png)</figure> Please upload your individual .java files, not a zip file. If you see this: <figure>[![Main not found](lab3res/mainNotFound.png)](lab3res/mainNotFound.png)</figure> Please upload [Kitchen.java](lab3res/Kitchen.java) as your main file, without modification (except to the package or to add your own recipes). If you see this: <figure>[![Tests not run](lab3res/testsNotRun.png)](lab3res/testsNotRun.png)</figure> Please fix the compile error and upload your code again. Note that warnings may be considered compile errors. Please check IntellIJ for the yellow warning messages and correct them. If your output matches the expected output exactly, you will not see any output, but you will see a message stating that the code compiled successfully (and none of the errors above!)