// Allison Obourn, CSE 142 // Prints a scalable diamond within a square made of ASCII characters. // NOTE: goals, pseudocode and loop tables should NOT appear in your final program's // comments. They appear here so you can recall what we did in lecture. public class Mirror { public static final int SIZE = 3; public static void main (String[] args) { drawLine(); drawTop(); drawBottom(); drawLine(); } // print #, 16 =, # // prints a line of equal signs with hashes on the ends public static void drawLine() { System.out.print("#"); for (int i = 1; i <= 4 * SIZE; i++) { System.out.print("="); } System.out.println("#"); } // top half: // for 4 lines { // print |, some spaces, <>, some dots, <>, some spaces, | // } /* line spaces -2 * line -2 * line + 6 1 4 -2 4 2 2 -4 2 3 0 -6 0 size equation 3 -2 * line + 6 4 -2 * line + 8 SIZE line * -2 + SIZE * 2 */ // draws an isosceles triangle that opens downwards public static void drawTop() { for (int line = 1; line <= SIZE; line++) { System.out.print("|"); for (int i = 1; i <= -2 * line + 2 * SIZE; i++) { System.out.print(" "); } System.out.print("<>"); for (int i = 1; i <= 4 * line - 4; i++) { System.out.print("."); } System.out.print("<>"); for (int i = 1; i <= -2 * line + 2 * SIZE ; i++) { System.out.print(" "); } System.out.println("|"); } } // the top and bottom are symmetrical so you can just make the // outer loop run backwards // draws an isosceles triangle that opens upwards public static void drawBottom() { for (int line = SIZE; line >= 1; line--) { System.out.print("|"); for (int i = 1; i <= -2 * line + SIZE * 2; i++) { System.out.print(" "); } System.out.print("<>"); for (int i = 1; i <= 4 * line - 4; i++) { System.out.print("."); } System.out.print("<>"); for (int i = 1; i <= -2 * line + SIZE * 2; i++) { System.out.print(" "); } System.out.println("|"); } } }