import
java.util.*;
public
class
Main {
static
class
Point {
double
x, y;
Point() { }
Point(
double
x,
double
y) {
this
.x = x;
this
.y = y;
}
@Override
public
boolean
equals(Object obj) {
if
(obj ==
this
)
return
true
;
if
(!(obj
instanceof
Point))
return
false
;
Point other = (Point) obj;
return
Double.compare(x, other.x) ==
0
&& Double.compare(y, other.y) ==
0
;
}
@Override
public
int
hashCode() {
return
Objects.hash(x, y);
}
}
static
Point getMidPoint(Point[] points,
int
i,
int
j) {
return
new
Point((points[i].x + points[j].x) /
2.0
,
(points[i].y + points[j].y) /
2.0
);
}
static
boolean
isParallelogram(Point[] points) {
Map<Point, List<Point>> midPointMap =
new
HashMap<>();
int
P =
4
;
for
(
int
i =
0
; i < P; i++) {
for
(
int
j = i +
1
; j < P; j++) {
Point temp = getMidPoint(points, i, j);
if
(!midPointMap.containsKey(temp)) {
midPointMap.put(temp,
new
ArrayList<>());
}
midPointMap.get(temp).add(
new
Point(i, j));
}
}
int
two =
0
, one =
0
;
for
(List<Point> pointsList : midPointMap.values()) {
int
size = pointsList.size();
if
(size ==
2
) {
two++;
}
else
if
(size ==
1
) {
one++;
}
else
{
return
false
;
}
}
if
(two ==
1
&& one ==
4
) {
return
true
;
}
return
false
;
}
public
static
void
main(String[] args) {
Point[] points =
new
Point[
4
];
points[
0
] =
new
Point(
0
,
0
);
points[
1
] =
new
Point(
4
,
0
);
points[
2
] =
new
Point(
1
,
3
);
points[
3
] =
new
Point(
5
,
3
);
if
(isParallelogram(points)) {
System.out.println(
"Given points form a parallelogram"
);
}
else
{
System.out.println(
"Given points do not form a parallelogram"
);
}
}
}