-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolyhedron.java
More file actions
118 lines (101 loc) · 2.33 KB
/
Polyhedron.java
File metadata and controls
118 lines (101 loc) · 2.33 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
import java.util.Scanner;
/**
* Abstract Polyhedron Base Class
*/
public abstract class Polyhedron implements Cloneable{
/**
* A string representing the name of this polyhedron
*/
private String type;
/**
* Box (rectangular prism) that contains this element
*/
protected BoundingBox boundingBox;
/**
* Default Constructor
*/
public Polyhedron()
{
this.type = "Polyhedron";
this.boundingBox = new BoundingBox();
}
/**
* Constructor which allows
* a name to be set
*
* @param t c-string representing the polyhedron name
*/
public Polyhedron(String t)
{
this.type = t;
this.boundingBox = new BoundingBox();
}
/**
* Get the polyhedron name
*/
public String getType()
{
return this.type;
}
/**
* set the polyhedron name
*/
public void setType(String t)
{
this.type = t;
}
/**
* Retrieve the bounding box
*/
public BoundingBox getBoundingBox()
{
return this.boundingBox;
}
/**
* Retrieve and reconstruct the polyhedron
* from an input stream
*/
public abstract void read(Scanner s);
/**
* Apply a geometric scaling operation
*/
public abstract void scale(double scalingFactor);
/**
* Clone a Polyhedron and minimize casting
*/
public abstract Polyhedron clone();
/**
* Print the polyhedron
*/
public String toString()
{
return "[" + type + "] "
+ boundingBox.getUpperRightVertex()
+ "->";
}
/**
* Create and return a new Polyhedron. This
* is an object that is one of the three subtypes,
* Sphere, Cylinder, or Composite
*/
public static Polyhedron createAndRead(Scanner s)
{
Polyhedron ply = null;
String polyhedronType = null;
if (s.hasNext()) {
polyhedronType = s.next();
ply = PolyhedronFactory.createPolyhedron(polyhedronType);
if (ply != null) {
ply.read(s);
}
else {
s.nextLine();
s.nextLine();
}
}
return ply;
}
}