// This program produces an ASCII art drawing of a mirror. // // This version adds a method to print the correct number of // spaces based on which line is being printed. Notice the // use of parameters in that method. public class Mirror3 { public static final int SIZE = 6; public static void main(String[] args) { line(); topHalf(); bottomHalf(); line(); } // Prints a line that appears at the top and bottom of the mirror. public static void line() { // # sign System.out.print("#"); // = signs for (int i = 1; i <= 4 * SIZE; i++) { System.out.print("="); } // # sign System.out.println("#"); } // Prints the top half of the mirror. public static void topHalf() { for (int line = 1; line <= SIZE; line++) { System.out.print("|"); // spaces printSpaces(line); System.out.print("<>"); // dots for (int i = 1; i <= 4 * line - 4; i++) { System.out.print("."); } System.out.print("<>"); // spaces printSpaces(line); System.out.println("|"); } } // Prints the bottom half of the mirror. public static void bottomHalf() { for (int line = SIZE; line >= 1; line--) { System.out.print("|"); // spaces printSpaces(line); System.out.print("<>"); // dots for (int i = 1; i <= 4 * line - 4; i++) { System.out.print("."); } System.out.print("<>"); // spaces printSpaces(line); System.out.println("|"); } } // Prints the correct number of spaces for the given line. // // int line - the line currently being printed public static void printSpaces(int line) { for (int i = 1; i <= -2 * line + 2 * SIZE; i++) { System.out.print(" "); } } }