/***************************************************************************** * Cooking.java written by Mark Rich * Jan 22, 2000 * Edited slightly by Eric Lantz 2006 * * This general class Cooking will be used to prepare various meals in the * kitchen. The only method currently written in * BakingCookies, an * implementation for baking a variation on Toll-House Chocolate Chip Cookies. * * Here's the original recipe: * * Ingredients: * 1 tsp. vanilla * 1 cup milk * 2 large eggs * 1 cup melted butter * 3 cups all purpose flour * 1 tsp. baking soda * 1/2 tsp. salt * 3/4 cup granulated sugar * 3/4 cup light brown sugar * 1 bag chocolate chips * * Directions: * Preheat oven to 375 F. In medium bowl, mix together dry ingredients flour, * baking soda, salt, granulated sugar and light brown * sugar. Stir together * vanilla, milk, eggs and melted butter in large bowl. Gradually add flour * mixture, beating until smooth. * Stir in chocolate chips. Pour batter into * greased 20 x 12 x 1 inch pan. Bake for 15 to 20 minutes until top is * browned. * Remove and enjoy! * * The program below is an attempt at a translation to Java of only the main * program flow. Creation and implementation of all the * ingredients and bowls, * etc, is left as an exercise to the reader. :) ******************************************************************************/ public class Cooking { /** * This method implements a recipe for * Chocolate-Chip Cookies. It is a static member of the * Cooking class, and will return 30 cookie bars to the * calling Object. There are no parameters to this method. **/ public static Cookie[] bakeCookies() { // Declare an Oven and preheat to 375. Oven oven = new Oven(); oven.set(375); // Declare Ingredients array with space for 10 ingredients Ingredient[] ingredients = new Ingredient[10]; // Add dry ingredients (flour, baking soda, salt, granulated // sugar and brown sugar) to the array. ingredients[0] = new Flour(3); ingredients[1] = new BakingSoda(1); ingredients[2] = new Salt(.5); ingredients[3] = new GranSugar(.75); ingredients[4] = new BrownSugar(.75); // Declare a medium-sized Bowl to hold the dry ingredients. Bowl medBowl = new Bowl("Medium"); // A "for" loop, to add the dry ingredients to the medium Bowl and stir. for (int i=0; i<5; i++) { medBowl.add(ingredients[i]); medBowl.stir(); } // Add wet ingredients (vanilla, milk, two eggs and butter) to // the ingredients array. ingredients[5] = new Vanilla(1); ingredients[6] = new Milk(1); ingredients[7] = new Egg("Large"); ingredients[8] = new Egg("Large"); ingredients[9] = new Butter(1); // Declare a large sized Bowl to eventually hold all ingredients. Bowl largeBowl = new Bowl("Large"); // Another "for" loop, adding the wet ingredients to the large // Bowl and stirring. for (int i=5; i<10; i++) { largeBowl.add(ingredients[i]); largeBowl.stir(); } // Add the flour mixture from the medium bowl into the large Bowl. largeBowl.add(medBowl.getMixture()); // A "while" loop, to beat the contents of the large Bowl // until it is smooth. while (largeBowl.isLumpy()) { largeBowl.stir(); } // Add Chocolate Chips to the large Bowl mixture and stir. largeBowl.add(new ChocChips(1)); largeBowl.stir(); // Declare a 20 x 12 x 1 inch pan and grease it. Pan pan = new Pan(20, 12, 1); pan.grease(); // Pour the mixed batter into the Pan pan.fill(largeBowl.getMixture()); // Place the pan in the preheated oven. oven.placeIn(pan); // Another "for" loop, this time running a timer for the oven. // We cook the pan for fifteen minutes for (int minutes=0; minutes<15; minutes++) { oven.cook(); } // Open the oven so you can see the Pan. oven.open(); // If it is not brown on top yet, close up the oven and keep cooking // for another five minutes. if (!pan.isBrowned()) { oven.close(); for (int minutes=0; minutes<5; minutes++) { oven.cook(); } } // Remove the pan from the oven. oven.remove(pan); // Slice into 30 cookies. pan.slice(30); // Return the cookies to the calling object. return pan.getContents(); } }