// CSE 142, Spring 2010 // // This program produces a text figure that looks like a mirror. // It uses nested loops to capture the repetition of characters on each line. // This version just draws the mirror at a fixed size. // See MirrorConstant.java for a version that scales using a constant. public class Mirror { public static void main(String[] args) { line(); topHalf(); bottomHalf(); line(); } // Draws the figure's top/bottom line of #===...===# . public static void line() { System.out.println("#================#"); } // Draws the top half of the mirror's center, // with patterns of lines represented by nested loops. public static void topHalf() { for (int line = 1; line <= 4; line++) { // print the contents of each line // | System.out.print("|"); // print a space, (-2 * line + 8) times for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } // <> System.out.print("<>"); // print a dot, (4 * line - 4) times for (int dot = 1; dot <= (4 * line - 4); dot++) { System.out.print("."); } // <> System.out.print("<>"); // print a space, (-2 * line + 8) times for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } // | System.out.println("|"); } } // Draws the bottom half of the mirror's center, // with patterns of lines represented by nested loops. // This is the same code as the top half, but the order of // the lines has been reversed. public static void bottomHalf() { for (int line = 4; line >= 1; line--) { // print the contents of each line // | System.out.print("|"); // print a space, (-2 * line + 8) times for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } // <> System.out.print("<>"); // print a dot, (4 * line - 4) times for (int dot = 1; dot <= (4 * line - 4); dot++) { System.out.print("."); } // <> System.out.print("<>"); // print a space, (-2 * line + 8) times for (int space = 1; space <= (-2 * line + 8); space++) { System.out.print(" "); } // | System.out.println("|"); } } }