/* BoxText written by Keith Fenske Saturday, 11 May 2002 Copyright (c) 2002 by Keith Fenske. All rights reserved. This assignment is practice in writing Java methods. (Other programming languages use the words "function", "procedure", or "subroutine".) Three static class methods are created. boxText() draws a box around a string of text using the characters "+", "-", and "|". boxText() calls a second method named boxLine() to draw the horizontal lines. boxText() is called by a third method named boxInfo() which formats a person's name and age into a message string. */ public class BoxText { public static void main(String[] args) { boxLine(0); // test boxLine() method boxLine(10); boxText("Hello. How are you?"); // test boxText() method boxText("12345678901234567890123456789012345678901234567890123456789012345678901234567"); boxInfo("Mickey Mouse", 73); // test boxInfo() method boxInfo("Tyrannosaurus rex", 65000000); } /* boxInfo() method This method takes two parameters. The first parameter is a string with a person's name. The second parameter is an integer with that person's age. This method prints a message inside a box with information about the person. */ static void boxInfo(String name, int age) { boxText(name + " is " + age + " years old."); } /* boxLine() method This method prints a horizontal line whose length is equal to the integer parameter. The characters "+" and "-" are used to draw the line. */ static void boxLine(int length) { int i; // index variable in "for" loop System.out.print("+"); // left side of line for (i = 0; i < length; i ++) System.out.print("-"); // draw line one dash at a time System.out.println("+"); // right side of line } /* boxText() method This method takes a string parameter and prints a box around the string. The characters "+", "-", and "|" are used to draw the box. */ static void boxText(String words) { int size; // length of string in characters System.out.println(); // put blank line in output size = words.length(); // get length of string in characters boxLine(size); // print top line System.out.println("|" + words + "|"); // our parameter boxLine(size); // print bottom line } } // end of class