/* Helene Martin, CSE 142 Outputs an ASCII mirror. (This file contains a lot of information about the design process. Please limit your own comments to short descriptions of behavior. You may want to do some of the design in comments and then remove them. See MirrorFinal.java for an example of a finalized program.) #================# | <><> | a | <>....<> | b | <>........<> | c |<>............<>| d |<>............<>| d | <>........<> | c | <>....<> | b | <><> | a #================# */ public class Mirror { // number of lines in the top and bottom halves public static final int SIZE = 4; public static void main(String[] args) { drawLine(); drawTop(); drawBottom(); drawLine(); } // displays a line of equal signs public static void drawLine() { System.out.print("#"); for(int i = 1; i <= 4 * SIZE; i++) { System.out.print("="); } System.out.println("#"); } /* (Don't leave this in your final program) pseudocode: | <><> | for each of 4 lines: | <>....<> | | (pipe), line * -2 + 8 spaces, <>, line * 4 - 4 dots, <>, line * -2 + 8 spaces, | | <>........<> | |<>............<>| line spaces line * -2 line * -2 + 8 dots line * 4 - 4 1 6 -2 6 0 2 4 -4 4 4 3 2 -6 2 8 4 0 -8 0 12 Scaling the figure SIZE spaces dots 4 line * -2 + 8 line * 4 - 4 3 line * -2 + 6 line * 4 - 4 line * -2 + SIZE * 2 SIZE has no effect! */ // displays a downward-facing triangle public static void drawTop() { for(int line = 1; line <= SIZE; line++) { System.out.print("|"); for(int spaces = 1; spaces <= line * -2 + SIZE * 2; spaces++) { System.out.print(" "); } System.out.print("<>"); for(int dots = 1; dots <= line * 4 - 4; dots++) { System.out.print("."); } System.out.print("<>"); for(int spaces = 1; spaces <= line * -2 + SIZE * 2; spaces++) { System.out.print(" "); } System.out.println("|"); } } /* (Don't leave this in your final program) We could have gone through the same process as for the top to figure out expressions. But we cleverly(!) noticed that the top and bottom have common lines. We ran the outer loop in the opposite direction. We tried putting the redundant inner loops in a method but we saw that the line variable was then out of scope. */ // displays an upward-facing triangle public static void drawBottom() { for(int line = SIZE; line >= 1; line--) { System.out.print("|"); for(int spaces = 1; spaces <= line * -2 + SIZE * 2; spaces++) { System.out.print(" "); } System.out.print("<>"); for(int dots = 1; dots <= line * 4 - 4; dots++) { System.out.print("."); } System.out.print("<>"); for(int spaces = 1; spaces <= line * -2 + SIZE * 2; spaces++) { System.out.print(" "); } System.out.println("|"); } } }