-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.java
69 lines (54 loc) · 1.39 KB
/
Circle.java
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
66
67
68
69
package CS102_reUP.HangmanGame.Lab03_Part2;
/**
* @ author Zeynep Doga Dellal
* @ date 2.11.2021
*/
public class Circle extends Shape implements Selectable {
int radius;
boolean selected;
public Circle(){
this.radius=0;
}
public Circle(int radius, int x, int y){
this.radius = radius;
setLocation(x, y);
}
public void setRadius(int radius) {
this.radius = radius;
}
public int getRadius() {
return this.radius;
}
public double getArea(){
return (Math.PI)*radius*radius;
}
public double getPerimeter() {
return Math.PI*2*radius;
}
public boolean getSelected(){
return selected;
}
public void setSelected(boolean selected){
this.selected = selected;
}
public Shape contains(int x, int y){
if((getX() - x) * (getX() - x) +
(getY() - y) * (getY() - y) <= radius * radius){
return this;
}
return null;
}
public boolean isSelected() {
return this.selected;
}
public String getInfo(){
String s = "Circle's radius is: " + radius;
if(getSelected()){
s = s + " and square is selected.";
}
else{
s = s + " and square is not selected.";
}
return s;
}
}