// Whitaker Brand // Lecture 2 // // This class is an example of using static methods to reduce redundancy. // Note, this program produces one figure, twice, using two different strategies. // The first way is the correct and preferred way. public class Complex { // Draws a 'lid' shaped structure // Note that this method can go here (or down much below): public static void lid() { System.out.println(" ______"); System.out.println(" / \\"); System.out.println(" / \\"); } public static void main(String[] args) { // The better way to produce the output: // Uses static methods to re-use code // to do the same thing a couple times: lid(); System.out.println(" \\ /"); System.out.println(" \\______/"); lid(); lid(); // The worse way to produce the same output: // This strategy doesn't "reduce the redunancy" -- // that is to say, we have duplicated code. System.out.println(" ______"); System.out.println(" / \\"); System.out.println(" / \\"); System.out.println(" \\ /"); System.out.println(" \\______/"); System.out.println(" ______"); System.out.println(" / \\"); System.out.println(" / \\"); System.out.println(" ______"); System.out.println(" / \\"); System.out.println(" / \\"); } // Note that we could have also put the lid() method and contents // down here -- it works the same as having it before main(). // // public static void lid() { ... } }