// CSE 142 Lecture 5 // Parameters // Draw an ascii art mirror that can scale based on SIZE constant. public class MirrorSlick { public static final int SIZE = 4; public static void main(String[] args) { line(); halfFigure(1, SIZE + 1, 1); halfFigure(SIZE, 0, -1); line(); } // Prints the line at the top or bottom of the figure. public static void line() { System.out.print("#"); repeat("=", 4 * SIZE); System.out.println("#"); } // Prints the upper or lower half of the mirror depending on the // parameters passed. The parameters we pass run the loop backwards // or forwards. // In class I lied and said we could use 2 params...we need three. public static void halfFigure(int start, int end, int update) { for (int line = start; line != end; line += update) { System.out.print("|"); repeat(" ", line * -2 + 2 * SIZE); System.out.print("<>"); repeat(".", line * 4 - 4); System.out.print("<>"); repeat(" ", line * -2 + 2 * SIZE); System.out.println("|"); } } // Prints s count times on the same line. public static void repeat(String s, int count) { for (int i = 1; i <= count; i++) { System.out.print(s); } } }