
class Line extends Polygon
{
  // Instance variables

  Point p1 = new Point(),	// one end point of line. Note initializations
        p2 = new Point();	// other end point

  public Line()			// zero-param Constructor
  { }				// Point constructor initializes both pts
				// to (0,0)

  public Line( Point start, Point end )	// 2-param constructor
  {
     p1.x = start.x; p1.y = start.y;
     p2.x = end.x;   p2.y = end.y;
  }

  public double slope()		// Compute the slope of a line
  {
     return ( - (double)(p2.y - p1.y)/(p2.x - p1.x) );
     // Must negate usual formula for slope because y coordinate
     // increases as it moves down the page.
  }

  public boolean isParallel( Line L )	// Return true if instance
  {					// is parallel to L.
     return ( this.slope() == L.slope() );
  }

  public void paint( Graphics g )	// Paint line on grid
  { g.drawLine( p1.x,p1.y, p2.x,p2.y ); }
}
