java /** * Returns a String of length width that begins and ends with the charac
ID: 3747277 • Letter: J
Question
java
/**
* Returns a String of length width that begins and ends with the character edge and contains width-2 copies of the
* character inner in between. The method does not print anything.
*
* Example makeLine('+', '-', 8) is "+------+".
*
* IMPLEMENTATION NOTE: Use an accumulation loop
*
* @params width must be >= 2
*/
/**
* Returns a string which, when printed out, will be a rectangle shaped something like this:
*
* <pre>
* +----------+
* | |
* | |
* | |
* | |
* | |
* +----------+
* </pre>
*
* The returned string should consist of height lines, each ending with a newline. In addition to the newline, the
* first and last lines should begin and end with '+' and should contain width-2 '-' symbols. In addition to the
* newline, the other lines should begin and end with '|' and should contain width-2 spaces. The method does not
* print anything.
*
* IMPLEMENTATION NOTE: For full credit (and for easier implementation), make use of the makeLine method in your
* implementation of makeRectangle. Use an accumulation loop.
*
* @param height must be >= 2
* @param width must be >= 2
*/
Explanation / Answer
public class MakeRectangle { /** * Returns a String of length width that begins and ends with the character edge and contains width-2 copies of the * character inner in between. The method does not print anything. * * Example makeLine('+', '-', 8) is "+------+". * * IMPLEMENTATION NOTE: Use an accumulation loop * * @params width must be >= 2 */ /** * Returns a string which, when printed out, will be a rectangle shaped something like this: * ** +----------+ * | | * | | * | | * | | * | | * +----------+ ** * The returned string should consist of height lines, each ending with a newline. In addition to the newline, the * first and last lines should begin and end with '+' and should contain width-2 '-' symbols. In addition to the * newline, the other lines should begin and end with '|' and should contain width-2 spaces. The method does not * print anything. * * IMPLEMENTATION NOTE: For full credit (and for easier implementation), make use of the makeLine method in your * implementation of makeRectangle. Use an accumulation loop. * * @param height must be >= 2 * @param width must be >= 2 */ public static String makeRectangle(int height, int width) { String header = "+"; String normalLine = "|"; for(int i = 0; i
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.