// This program produces an ASCII art drawing of a tapestry. // // 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 Tapestry3 { public static final int SIZE = 6; public static void main(String[] args) { fringe(); topHalf(); bottomHalf(); fringe(); } // Prints the fringe that appears at the top and bottom of the tapestry. public static void fringe() { // # 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 tapestry. 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 tapestry. 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(" "); } } }