// Tyler Rigsby, CSE 142 // Prints a mirror figure using ASCII characters // Note: I have included here the drawings, loop tables, and pseudocode // used in class to illustrate our progression. These should all be left // out of your personal code when you turn in. /* #================# | <><> | 1 | <>....<> | 2 | <>........<> | 3 |<>............<>| 4 |<>............<>| 4 | <>........<> | 3 | <>....<> | 2 | <><> | 1 #================# */ public class Mirror { public static final int SIZE = 3; public static void main(String[] args) { drawLine(); drawTopHalf(); drawBottomHalf(); drawLine(); } // #================# public static void drawLine() { System.out.print("#"); for (int equals = 1; equals <= 4 * SIZE; equals++) { System.out.print("="); } System.out.println("#"); } /* | <><> | 1 | <>....<> | 2 | <>........<> | 3 |<>............<>| 4 line dots 4 * line 4 * line - 4 1 0 4 0 2 4 8 4 3 8 12 8 4 12 16 12 line spaces -2 * line -2 * line + 8 1 6 -2 6 2 4 -4 4 3 2 -6 2 4 0 -8 0 */ // Draws the top half of the mirror figure public static void drawTopHalf() { /* for (each of 4 lines) { | some spaces (decreasing) <> some dots (increasing) <> some spaces (decreasing) | } */ for (int line = 1; line <= SIZE; line++) { System.out.print("|"); for (int spaces = 1; spaces <= -2 * line + 2 * SIZE; 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("|"); } } // Draws the bottom half of the mirror figure public static void drawBottomHalf() { // same as above, just with line taking the values in the reverse order for (int line = SIZE; line >= 1; line--) { System.out.print("|"); for (int spaces = 1; spaces <= -2 * line + 2 * SIZE; 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("|"); } } } /* loop tables for constant: const expression ( ) 3 -2 * line + 6 4 -2 * line + 8 SIZE -2 * line + 2 * SIZE constant expression (=) 3 12 4 16 SIZE 4 * SIZE */