public class Segment { private Point p1, p2; public Point getP1(){ return p1; } public Point getP2(){ return p2; } public void setPoint2(Point p){ p2 = p; } public void setPoint1(Point p){ p1 = p; } Segment(Point p1, Point p2){ this.p1 = p1; this.p2 = p2; } public double getLength(){ double dx = p1.x - p2.x; double dy = p1.y - p2.y; double length = dx*dx + dy*dy; length = Math.sqrt(length); return length; } }