-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
36 lines (32 loc) · 739 Bytes
/
Copy pathCircle.java
File metadata and controls
36 lines (32 loc) · 739 Bytes
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
32
33
34
35
36
package lab_2_exercises;
import java.awt.geom.Point2D;
public class Circle {
private int x;
private int y;
private int radius;
public Circle(int x, int y, int radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
public void setCenter(int x, int y) {
this.x = x;
this.y = y;
}
public void setRadius(int radius) {
this.radius = radius;
}
public int getRadius() {
return radius;
}
public boolean contains(int x, int y) {
int diff_0 = x - this.x;
int diff_1 = y - this.y;
return ((diff_0*diff_0 + diff_1*diff_1) <= radius*radius);
}
public Square enclosingSquare() {
int x = this.x - radius;
int y = this.y - radius;
return new Square(x, y, 2*radius);
}
}