-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.java
More file actions
42 lines (33 loc) · 1.01 KB
/
Circle.java
File metadata and controls
42 lines (33 loc) · 1.01 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
// subclass of shape.
// it is the only geometric shape that is not a polygon, which is why it inherits from shape and also why shape is the super class of polygon despite them both being abstract classes.
public class Circle extends Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
@Override
public String getName() {
return "Circle";
}
@Override
public double getPerimeter() { // circumference
return 2 * Math.PI * radius;
}
@Override
public double getArea() {
return Math.PI * radius * radius;
}
public double getDiameter() {
return 2 * radius;
}
@Override
public String toString() {
return String.format(
"Circle: Radius: %.2f, Diameter: %.2f, Circumference: %.2f, Area: %.2f]",
radius,
getDiameter(),
getPerimeter(),
getArea()
);
}
}