-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
33 lines (31 loc) · 1.01 KB
/
Circle.java
File metadata and controls
33 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class Circle extends GeometricFigure implements Calculate {
private double ratio;
private Dot center;
public Circle(int x, int y, double ratio, String color){
super(color);
this.center = new Dot(x, y);
this.ratio = ratio;
}
@Override
public boolean compare(GeometricFigure fig) {
Circle c = (Circle) fig; //casting
return this.center.equals(c.center) &&
this.ratio == c.ratio &&
this.getColor().equals(c.getColor());
}
@Override
public double area() {
//A = π * r2
return Math.PI * this.ratio*this.ratio;
}
@Override
public double perimeter() {
//P = 2π * r
return 2*Math.PI * (this.ratio);
}
public boolean intersection (Circle c){
//If the distance of circle centers are lower than the sum of the ratios, then it areoverlapping
double centerDistance = this.center.distance(c.center);
return centerDistance <= this.ratio + c.ratio;
}
}