public class Line
{
  private int width;
  private char theLine[];
  private char fill;

  public Line(int width, char f)
  {
    this.width = width;
    this.fill = f;
    this.theLine = new char[this.width];
    for(int i = 0; i < this.width; i++)
      theLine[i] = this.fill;
  }

  public Line(int width)
  {
    this(width, ' ');
  }

  public void setPixel(int x, char c)
  {
    if(x >= 0 && x < this.width)
    {
      this.theLine[x] = c;
    }
  }

  public char getPixel(int x)
  {
    if(x < 0 || x >= this.width)
    {
      return fill;
    }
    else
    {
      return this.theLine[x];
    }
  }

  public int getWidth()
  {
    return this.width;
  }

  public String toString()
  {
    String retval = "";
    for(int i = 0; i < width; i++)
    {
      retval += this.theLine[i];
    }
    return retval;
  }

  public static void main(String args[])
  {
    Line myLine = new Line(25, 'M');
    System.out.println(myLine);
    myLine.setPixel(12, ' ');
    System.out.println(myLine);
    for(int i = 0; i < myLine.getWidth(); i++)
    {
      if(myLine.getPixel(i) == 'M')
        myLine.setPixel(i, 'P');
    }
    System.out.println(myLine);
  }
}


  
