-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImmutable
More file actions
54 lines (44 loc) · 1.33 KB
/
Immutable
File metadata and controls
54 lines (44 loc) · 1.33 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
public class Immutable {
private final double centreX, centreY, radius;
private static int numCircles;
public Immutable(double newCentreX, double newCentreY, double newRadius) {
centreX = newCentreX;
centreY = newCentreY;
radius = newRadius;
numCircles++;
}
public double getCentreX() {
return centreX;
}
public double getCentreY() {
return centreY;
}
public double getRadius() {
return radius;
}
public double computeCircumference () {
double circum = 2 * Math.PI * radius;
return circum;
}
public double computeArea () {
double area = Math.PI * radius * radius;
return area;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ImmutableCircle circle = (ImmutableCircle) o;
return Double.compare(circle.centreX, centreX) == 0 &&
Double.compare(circle.centreY, centreY) == 0 &&
Double.compare(circle.radius, radius) == 0;
}
@Override
public String toString() {
return "Circle: {" +
"centreX=" + centreX +
", centreY=" + centreY +
", radius=" + radius +
'}';
}
}