// CSE 142, Autumn 2010 // Author: Marty Stepp // This program uses parameters to draw several lines and boxes of stars. // The parameters allow each method to draw lines/boxes of different sizes. public class Stars { public static void main(String[] args) { lineOfStars(13); lineOfStars(7); lineOfStars(35); System.out.println(); box(5, 6, " "); box(10, 3, "."); box(70, 20, "#"); } // Draws a box of the given width and height. // This version accepts a third parameter representing what character to put // inside the middle of the box. // Examples: // // 5x6 box 10x3 box // ***** ********** // * * * * // * * ********** // * * // * * // ***** public static void box(int width, int height, String filling) { lineOfStars(width); // top for (int line = 1; line <= height - 2; line++) { // middle System.out.print("*"); for (int space = 1; space <= width - 2; space++) { System.out.print(filling); } System.out.println("*"); } lineOfStars(width); // bottom } // Draws a line of stars of the given length. // Example: lineOfStars(10) draws **********. public static void lineOfStars(int stars) { for (int i = 1; i <= stars; i++) { System.out.print("*"); } System.out.println(); } }