Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Line {
- private Point p1, p2;
- public Line(Point p1, Point p2) {
- this.p1 = p1;
- this.p2 = p2;
- }
- public Line(Line aLine) {
- this.p1 = aLine.p1;
- this.p2 = aLine.p2;
- }
- public Line() {
- this.p1 = new Point(0,0);
- this.p2 = new Point(0,0);
- }
- public Point getP1() {
- return p1;
- }
- public Point getP2() {
- return p2;
- }
- public void set(Point p1, Point p2) {
- this.p1 = p1;
- this.p2 = p2;
- }
- public double getDistance() {
- double xCoord = Math.pow((p1.getX() - p2.getX()),2);
- double yCoord = Math.pow((p1.getY() - p2.getY()), 2);
- return Math.sqrt(xCoord + yCoord);
- }
- public String toString() {
- return String.format("Line ( " + p1.toString() + ", " + p2.toString() + ", distance = %," +
- ".4f)\n", this.getDistance());
- }
- }
Add Comment
Please, Sign In to add comment