Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions task04/src/com/example/task04/Line.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.task04;

public class Line {
private final Point p1;
private final Point p2;

public Line(Point p1, Point p2){
this.p1 = p1;
this.p2 = p2;
}

public Point getP1() {
return p1;
}

public Point getP2() {
return p2;
}

public String toString() {
return String.format("%d, %d", p1.toString(), p2.toString());
}

public boolean isCollinearLine(Point p) {
return Math.abs(p.distance(p1) + p.distance(p2) - p1.distance(p2)) < 1e-10;
}
}
35 changes: 35 additions & 0 deletions task04/src/com/example/task04/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.task04;

public class Point {
int x;
int y;

public Point(int x, int y) {
this.x = x;
this.y = y;
}

public Point() {

}

void print() {
String pointToString = String.format("(%d, %d)", x, y);
System.out.println(pointToString);
}

void flip() {
int tmp;
tmp = x;
x = -y;
y = -tmp;
}

double distance(Point point) {
return Math.sqrt(Math.pow((x - point.x), 2) + Math.pow((y - point.y), 2));
}

public String toString() {
return "(" + x + "," + y + ")";
}
}