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:
|
class Sphere {
private int x;
private int y;
private int z;
private double radius;
public Sphere(int x, int y, int z, double r){
this.x = x;
this.y = y;
this.z = z;
this.radius = r;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public int getZ(){
return z;
}
double getRadius(){
return radius;
}
double calculateDiameter(){
return 2 * radius;
}
double calculateSurfaceArea(){
return 4 * Math.PI * Math.pow(radius, 2);
}
double calculateVolume(){
return 4 / (float)3 * Math.PI * Math.pow(radius, 3);
}
public static void main(String[] args){
Sphere s = new Sphere(0, 0, 0, 7);
System.out.println(s.calculateDiameter());
System.out.println(s.calculateSurfaceArea());
System.out.println(s.calculateVolume());
}
}
|