// We're using static methods to: // 1. Create Structure // 2. Eliminate Redundancy // both of which are equally important. We want our main to be // a high level summary, or table of contents, of the behavior of our program. // We also want to remove redundancy (multiple lines of code that appear in // multiple places) in order to shorten our code and make it easier to maintain. public class BakeCookiesAnnotated { public static void main(String[] args) { // main is a concise summary of the behavior of our program mixIngredients(); bakeCookies(); bakeCookies(); bakeCookies(); frostCookies(); } // These lines of code only appear once in our output, but they are // logically related and part of a single task, so we put them in a method // to add structure to our program and make main more readable. public static void mixIngredients() { System.out.println("Mix the dry ingredients."); System.out.println("Cream the butter and sugar."); System.out.println("Beat in the eggs."); System.out.println("Stir in the dry ingredients."); System.out.println(); } // These lines of code appear in the output multiple times. Creating a // method for baking cookies allows us to simple call bakeCookies() // three times to make three batches of cookies. public static void bakeCookies() { System.out.println("Set the oven temperature to 350 degrees."); System.out.println("Set the timer for 20 minutes."); System.out.println("Place the cookies into the oven."); System.out.println("Allow the cookies to bake."); } // These lines of code only appear once in our output, but they are // logically related and part of a single task, so we put them in a method // to add structure to our program and make main more readable. public static void frostCookies() { System.out.println("Mix the ingredients for the frosting."); System.out.println("Spread frosting and sprinkles onto the cookies."); System.out.println(); } } // Other style notes: // * We place a blank line in between methods to make our code more readable. // * Method names are "camelCased." The method name starts with a lowercase // letter and each subsequent begins with an uppercase letter.