-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphere.java
More file actions
37 lines (27 loc) · 811 Bytes
/
Sphere.java
File metadata and controls
37 lines (27 loc) · 811 Bytes
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
package javapro;
class Sphere extends ThreeDShape{
static final String CLASS_NAME = "Sphere";
Circle circle1; //composition
public Sphere(String name, double rad) {
super(name,rad,rad,rad);
circle1 = new Circle(name, rad);
}
public String getClassName() {
return CLASS_NAME;
}
public double getRadious() {
return super.getDimension1();
}
public void setRadious(double rad) {
super.setDimension1(rad);
super.setDimension2(rad);
super.setDimension3(rad);
} //It's because Sphere needs radius three times
public double getVolume() {
return Math.PI* 4/3 * super.getDimension1()*super.getDimension2()*super.getDimension3();
}
public String toString() {
return String.format("%s is a [%s], and is a [%s]",
super.getName(), getClassName(), super.getClassName());
}
}