-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSphere.java
86 lines (73 loc) · 1.55 KB
/
Sphere.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
import java.util.Scanner;
/**
* Sphere
*/
public class Sphere extends Polyhedron {
private double radius;
/**
* Default Constructor
*/
public Sphere()
{
super("Sphere");
this.radius = 0;
}
/**
* Construct a sphere from a provided radius
*/
public Sphere(double r)
{
super("Sphere");
this.radius = r;
double d = this.getDiameter();
this.boundingBox.setUpperRightVertex(d, d, d);
}
/**
* Retrieve the radius
*/
public double getRadius()
{
return this.radius;
}
/**
* Update the radius
*/
public void setRadius(double r)
{
this.radius = r;
double d = getDiameter();
boundingBox.setUpperRightVertex(d, d, d);
}
/**
* Compute and return the diameter
*/
public double getDiameter()
{
return 2 * this.radius;
}
public void read(Scanner scanner)
{
this.radius = scanner.nextDouble();
double d = this.getDiameter();
boundingBox.setUpperRightVertex(d, d, d);
}
public void scale(double scalingFactor)
{
this.radius *= scalingFactor;
this.boundingBox.scale(scalingFactor);
}
public Polyhedron clone()
{
return new Sphere(this.radius);
}
public String toString()
{
return super.toString()
+ "Radius: " + this.radius
+ " "
+ "Diameter: " + this.getDiameter();
}
}