-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
53 lines (52 loc) · 1.44 KB
/
Copy pathCircle.java
File metadata and controls
53 lines (52 loc) · 1.44 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
// Circle
import java.lang.Math;
import java.util.ArrayList;
public class Circle implements Shape {
public double radius;
public double x;
public double y;
public Circle(double radius, double x, double y){
this.radius = radius;
this.x = x;
this.y= y;
}
@Override
public double area() {
return (Math.PI*(this.radius*this.radius));
}
@Override
public double perimeter() {
return (Math.PI*(this.radius+this.radius));
}
/**
* This method moves a shape to another location
* in relation to its center, by adding the params offsetX and offsetY to its
* center coordinate.
* @param offsetX
* @param offsetY
*/
public void move(double offsetX, double offsetY){
this.x = this.x + offsetX;
this.y = this.y + offsetX;
}
public double getRadius(){
return this.radius;
}
public void setRadius(double rad){
this.radius = rad;
}
public ArrayList<Double> getCenter(){
ArrayList<Double> a = new ArrayList<>();
a.add(this.x);
a.add(this.y);
return a;
}
public void setCenter(double sX, double sY){
this.x = sX;
this.y = sY;
}
@Override
public String toString(){
return "Circle Info: \nCentroid Coordinate: ("+this.x + ","+this.y+")" + "\nRadius length: " + this.radius;
}
}