// This program produces as output an ASCII art representation of a mirror. // This version includes a class constant for drawing mirrors of different // sizes. The constant SIZE represents the number of lines in one half of the // overall figure. // // We noticed that there were 12 ='s in the solid line for a size of 3 versus // 16 for a size of 4, so we made this table to develop an expression for the // number of ='s to use: // // SIZE ='s // 3 12 // 4 16 // // 4 * SIZE // // Then we used this table to recompute an expression for spaces and dots: // // line spaces dots // 1 4 0 // 2 2 4 // 3 0 8 // // -2 * line + 6 4 * line - 4 // // Then we made a table that showed the different formulas for different sizes // so that we could develop an expression that correctly adjusted for size: // // SIZE spaces dots // 3 -2 * line + 6 4 * line - 4 // 4 -2 * line + 8 4 * line - 4 // // -2 * line + 2 * SIZE (unchanged) public class Mirror2 { public static final int SIZE = 7; // change this to scale the mirror public static void main(String[] args) { drawLine(); drawTopHalf(); drawBottomHalf(); drawLine(); } // outputs a solid line public static void drawLine() { System.out.print("#"); for (int i = 1; i <= 4 * SIZE; i++) { System.out.print("="); } System.out.println("#"); } // outputs the top half of the mirror public static void drawTopHalf() { 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("|"); } } // same as top half only in reverse order public static void drawBottomHalf() { 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("|"); } } }