-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
45 lines (37 loc) · 1.14 KB
/
Copy pathCircle.java
File metadata and controls
45 lines (37 loc) · 1.14 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
public class Circle extends Point {
private int radius;
public Circle(){
super();
this.radius = 1;
}
public Circle(int x ,int y, String color, int radius){
super(x, y, color);
this.radius = radius;
}
public Circle(Circle other){
super(other);
this.radius = other.radius;
}
public int getRadius(){
return radius;
}
public void setRadius(int radius){
this.radius = radius;
}
@Override
public double area() {
return Math.PI * radius * radius;
}
public void scale(int scalefactor){
this.radius *= scalefactor;
}
public String string(){
return "Radius : " + this.radius +
"\nX and y : " + getX() + " , " + getY() + ". Color : " + getColor() ;
}
public Circle merge(Circle other){
double distance = Math.sqrt(Math.pow(this.getX() - this.getY(), 2) + Math.pow(this.getY() - other.getY(),2));
int newRadius = this.radius + (int) distance;
return new Circle(other.getX(),other.getY(),other.getColor(), newRadius);
}
}