-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCylinder.java
More file actions
91 lines (75 loc) · 1.72 KB
/
Cylinder.java
File metadata and controls
91 lines (75 loc) · 1.72 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
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
87
88
89
90
91
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
import java.util.Scanner;
class Cylinder extends Polyhedron {
private double height;
private double radius;
/**
* Default Constructor
*/
Cylinder()
{
super("Cylinder");
this.radius = 0;
this.height = 0;
}
/**
* Construct a cylinder with
* specified height and radius
*/
Cylinder(double r, double h)
{
super("Cylinder");
this.radius = r;
this.height = h;
double d = this.getDiameter();
this.boundingBox.setUpperRightVertex(d, d, height);
}
/**
* Retrieve the radius
*/
double getRadius()
{
return this.radius;
}
/**
* Update the radius
*/
void setRadius(double r)
{
this.radius = r;
double d = getDiameter();
this.boundingBox.setUpperRightVertex(d, d, height);
}
/**
* Compute and return the diameter
*/
double getDiameter()
{
return this.radius * 2;
}
public Polyhedron clone()
{
return new Cylinder(this.radius, this.height);
}
public void read(Scanner scanner)
{
this.height = scanner.nextDouble();
this.radius = scanner.nextDouble();
double d = this.getDiameter();
this.boundingBox.setUpperRightVertex(d, d, height);
}
public void scale(double scalingFactor)
{
this.radius *= scalingFactor;
this.height *= scalingFactor;
this.boundingBox.scale(scalingFactor);
}
public String toString()
{
return super.toString()
+ "Radius: " + this.radius + " "
+ "Height: " + this.height;
}
}