-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
65 lines (52 loc) · 1.11 KB
/
Circle.java
File metadata and controls
65 lines (52 loc) · 1.11 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// *** Your name:
import java.awt.Color;
import java.awt.Graphics;
public class Circle {
private int x;
private int y;
private int radius;
private Color color;
public Circle(int x, int y, int radius, Color color) {
this.x = x;
this.y = y;
this.radius = radius;
this.color = color;
}
public void draw(Graphics g) {
g.setColor(color);
g.fillOval(x, y, 2 * radius, 2 * radius);
g.setColor(Color.black);
g.drawOval(x, y, 2 * radius, 2 * radius);
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getWidth() {
return 2 * radius;
}
public int getHeight() {
return 2 * radius;
}
public Color getColor() {
return color;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setRadius(int radius) {
this.radius = radius;
}
public boolean containsPoint(int x, int y) {
//implement this method
int centerX = this.x + radius;
int centerY = this.y + radius;
double distance = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2));
return distance <= radius;
}
}