SHARE
TWEET

Untitled

advictoriam Mar 4th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* TODO:
  2.    Complete the class definition. Supply the body of the constructor
  3.    and any instance fields.
  4. */
  5.  
  6. /**
  7.    A rectangle whose interior is filled with a pattern
  8.    obtained by repeating a character.
  9. */
  10. public class FilledRectangle extends Rectangle
  11. {
  12.    /**
  13.       Constructs a rectangle with a given width, height, and fill
  14.       @param aWidth the width (including the corners)
  15.       @param aHeight the height (including the corners)
  16.       @param aFill the fill character
  17.    */
  18.    private char fill;
  19.    public FilledRectangle(int aWidth, int aHeight, char aFill)
  20.    {
  21.       super(aWidth, aHeight);
  22.       fill = aFill;
  23.    }
  24.  
  25.  
  26.    /**
  27.       Prints one line of the rectangle.
  28.       @param i the line to print (1 <= i <= height)
  29.    */
  30.    public void printLine(int i)
  31.    {
  32.       if (i == 1 || i == getHeight())
  33.          printHelper('+', '-');
  34.       else
  35.          printHelper('|', fill);
  36.    }
  37.  
  38.  
  39.    // The following method tests your class
  40.  
  41.    public static void main(String[] args)
  42.    {
  43.       FilledRectangle fr = new FilledRectangle(10, 7, '*');
  44.       fr.print();
  45.    }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top