// Marty Stepp, CSE 142, Autumn 2007 // This program prints an ASCII text figure that // looks like a mirror. // This version uses a class constant to make the figure resizable. public class Mirror2 { public static final int SIZE = 4; // constant to change the figure size public static void main(String[] args) { line(); topHalf(); bottomHalf(); line(); } // Prints the top half of the rounded mirror. public static void topHalf() { for (int line = 1; line <= SIZE; line++) { // pipe System.out.print("|"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // <> System.out.print("<>"); // dots . for (int j = 1; j <= 4 * line - 4; j++) { System.out.print("."); } // <> System.out.print("<>"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // pipe System.out.println("|"); } } // Prints the bottom half of the rounded mirror. public static void bottomHalf() { for (int line = SIZE; line >= 1; line--) { // pipe System.out.print("|"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // <> System.out.print("<>"); // dots . for (int j = 1; j <= 4 * line - 4; j++) { System.out.print("."); } // <> System.out.print("<>"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // pipe System.out.println("|"); } } // Prints the #==# line at the top and bottom of the mirror. public static void line() { System.out.print("#"); for (int j = 1; j <= 4 * SIZE; j++) { System.out.print("="); } System.out.println("#"); } }