// Here is an annotated version of our program // Note that the pseudocode, ASCII Art and loop // tables are for your personal use in developing the program // and should be removed before submitting a final version of // the assignment. // // Our general development strategy: // 1. Design the overall structure of the program by identifying // important shapes in the output and creating method headers for // these shapes. // 2. For each method, write pseudocode to outline the algorithm for // drawing a shape // 3. Build a loop table for each expression to map the line number // to the number of characters on that line // 4. Once the code for the entire output is complete, add class constant // by comparing expressions between outputs of different sizes. public class TapestryAnnotated { public static final int SIZE = 50; public static void main(String[] args) { /* #================# | <><> | 1 | <>....<> | 2 | <>........<> | 3 |<>............<>| 4 |<>............<>| 4 | <>........<> | 3 | <>....<> | 2 | <><> | 1 #================# */ fringe(); topHalf(); bottomHalf(); fringe(); } /* const = 4 16 3 12 SIZE 4 * SIZE */ public static void fringe() { // # 16 ='s # System.out.print("#"); for (int equals = 1; equals <= 4 * SIZE; equals++) { System.out.print("="); } System.out.println("#"); } /* | <><> | 1 | <>....<> | 2 | <>........<> | 3 |<>............<>| 4 line spaces -2 * line -2 * line + 8 1 6 -2 6 2 4 -4 4 3 2 -6 2 4 0 -8 0 Table to figure out constant (do this after completing default size) const spaces 4 -2 * line + 8 3 -2 * line + 6 SIZE -2 * line + SIZE * 2 line dots 4 * line 4 * line - 4 1 0 4 0 2 4 8 4 3 8 12 8 4 12 16 12 const dots 4 4 * line - 4 3 4 * line - 4 SIZE 4 * line - 4 */ public static void topHalf() { /* for each of SIZE lines | some spaces <> some dots <> some spaces | */ for (int line = 1; line <= SIZE; line++) { System.out.print("|"); // Remember that partial line redundancy is OKAY, since we don't have // the tools to eliminate this type of redundany. for (int spaces = 1; spaces <= -2 * line + SIZE * 2; spaces++) { System.out.print(" "); } System.out.print("<>"); for (int dots = 1; dots <= 4 * line - 4; dots++) { System.out.print("."); } System.out.print("<>"); for (int spaces = 1; spaces <= -2 * line + 2 * SIZE; spaces++) { System.out.print(" "); } System.out.println("|"); } } /* |<>............<>| | <>........<> | | <>....<> | | <><> | Notice that this is the reverse of the top half so we can just run our outter loop bakwards to flip the lines upside down. */ public static void bottomHalf() { for (int line = SIZE; line >= 1; line--) { System.out.print("|"); for (int spaces = 1; spaces <= -2 * line + SIZE * 2; spaces++) { System.out.print(" "); } System.out.print("<>"); for (int dots = 1; dots <= 4 * line - 4; dots++) { System.out.print("."); } System.out.print("<>"); for (int spaces = 1; spaces <= -2 * line + SIZE * 2; spaces++) { System.out.print(" "); } System.out.println("|"); } } }