-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.java
65 lines (53 loc) · 1.65 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
public class Circle extends Shape {
private Point topLeftPoint;
private double diameter;
// create constructers
// empty
public Circle() {
topLeftPoint = new Point();
diameter = 0;
}
// with params
public Circle(double x, double y, double diameter) {
this.topLeftPoint = new Point(x, y);
this.diameter = diameter;
}
public void setTopLeftPoint(Point point) {
topLeftPoint = point;
}
//fix names
public Point getTopLeftPoint() {
return topLeftPoint;
}
public void setDiameter(double d) {
diameter = d;
}
public double getDiameter() {
return diameter;
}
public double area() {
return Math.PI * Math.pow(diameter, 2);
}
public double perimeter() {
return Math.PI * diameter;
}
public boolean contains(Point contains) {
if (contains.getX() > topLeftPoint.getX() && contains.getX() < topLeftPoint.getX() + diameter
&& contains.getY() > topLeftPoint.getY() && contains.getY() < topLeftPoint.getY() + diameter) {
return true;
} else {
return false;
}
}
public Point centroid() {
double a = this.diameter/2;
double xCenter = topLeftPoint.getX() + a;
double yCenter = topLeftPoint.getY() + a;
Point centroid = new Point(xCenter, yCenter);
return centroid;
}
// toString()
public String toString() {
return "Circle (" + this.topLeftPoint.getX() + ", " + this.topLeftPoint.getY() + "), diameter: " + this.diameter;
}
}