/** Represents a line vector in 2D */ class LineVec { /** Origin and destination of the vector */ public Point origin; public Point destn; public static void main(String[] args) { LineVec line = new LineVec(); line.setOrigin(5, 10); line.setDestn(15, 20); Point mid_pt = line.midPoint(); System.out.println(mid_pt.toStr()); } /** Constructor */ public LineVec() { origin = new Point(0, 0); destn = new Point(0, 0); } public LineVec(Point o1, Point d1) { origin = new Point(o1.x, o1.y); destn = new Point(d1.x, d1.y); } /** Set the origin */ public void setOrigin(double x1, double y1) { origin.setX(x1); origin.setY(y1); } /** Set the destn */ public void setDestn(double x1, double y1) { destn.setX(x1); destn.setY(y1); } /** Return the mid-point of the line */ public Point midPoint() { double midX; double midY; midX = (origin.x + destn.x)/2; midY = (origin.y + destn.y)/2; return new Point(midX, midY); } } // End class LineVec