Limited access

Upgrade to access all content for this subject

A programmer would like to create a class that prints block capital letters to the console using System.out.print() and System.out.println() statements. The letters can be either 5, 7, or 9 lines high and can have a specified width. Each letter is printed over each other in the console.

For example, the following two statements would print letters to the console as follows:

BlockLetters b = new BlockLetters("AE",5,6); //height = 5, width = 6
b.printLetters();

Console output:

******
*    *
******
*    *
*    *

******
*
*****
*
******

Consider the following partial design of the BlockLetters class.

public class BlockLetters 
{
    private String words;  // contains letters to be printed
    private int height;    // height (number of lines high)
    private int width;     // width (number of characters wide)

    public BlockLetters(String words, int height, int width)
    {
        // Implementation not shown
    }

    // Prints block letters one after another to the console.
    // Prerequisite: letter is an uppercase letter
    public void printLetters()
    {
        for (int i=0; i<words.length(); i++)
        {
            // Implementation not shown
        }
    }
}

Which of the following designs would be the BEST for this class?

I. Create individual methods to print each letter (named printA(), printB(), printC(), etc.) and conditionally call them within the printLetters() method.

II. Create separate methods to print a horizontal long bar (the width of the letter) and a horizontal short bar (one character shorter than the width of the letter) that can be called when printing an individual letter.

III. Create a method to print a vertical side bar (the height of the letter) that can be called when printing an individual letter.

A

I only.

B

I and II only.

C

I and III only.

D

II and III only.

E

I, II, and III.

Select an assignment template