-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeDShape.java
More file actions
248 lines (234 loc) · 5.15 KB
/
ThreeDShape.java
File metadata and controls
248 lines (234 loc) · 5.15 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
* This class demonstrates the methods of the ThreeDShape class.
* @author Ioannis Tzeneralis
* @version 1.0
*/
class ThreeDShape {
private double width;
private double height;
private double depth;
/**
* Default constructor.
* @param w The width
* @param h The height
* @param d The depth
*/
ThreeDShape(double w, double h, double d){
width = w;
height = h;
depth = d;
}
/**
* Parameterized constructor.
* @param w The width
* @param h The height
*/
ThreeDShape(double w, double h){
width = w;
height = h;
}
/**
* Parameterized constructor.
* @param w
*/
ThreeDShape(double x) {
width = height = depth = x;
}
/**
* This method returns the width of ThreeDShape.
* @return width
*/
double getWidth() { return width; }
/**
* This method returns the height of ThreeDShape.
* @return height
*/
double getHeight() { return height; }
/**
* This method returns the depth of ThreeDShape.
* @return depth
*/
double getDepth() { return depth; }
/**
* This method sets the Width.
* @param w The width of ThreeDShape.
*/
void setWidth(double w) { width = w; }
/**
* This method sets the Height.
* @param h The height of ThreeDShape.
*/
void setHeight(double h) { height = h; }
/**
* This method sets the Depth.
* @param d The depth of ThreeDShape.
*/
void setDepth(double d) { depth = d; }
}
/**
* This class demonstrates the methods of the Sphere class.
* @author Ioannis Tzeneralis
* @version 1.0
*/
class Sphere extends ThreeDShape {
private double r;
/**
* Default constructor.
* @param x The radius
*/
Sphere(double x){
super(2*x);
r=x;
}
/**
* This method returns the area of Sphere.
* @return 4*Math.PI*Math.sqrt(r);
*/
double E(){
return 4*Math.PI*Math.sqrt(r);
}
/**
* This method returns the volume of Sphere.
* @return (4/3)*Math.PI*(Math.sqrt(r)*r);
*/
double V(){
return (4/3)*Math.PI*(Math.sqrt(r)*r);
}
/**
* This method prints the dimensions of Sphere.
*/
void show() {
System.out.println("R is: " + r + "\n");
}
}
/**
* This class demonstrates the methods of the Cylinder class.
* @author Ioannis Tzeneralis
* @version 1.0
*/
class Cylinder extends ThreeDShape {
private double r;
/**
* Default constructor.
* @param x The radius
* @param y The width or Hight
*/
Cylinder(double x, double y){
super(y);
r=x;
}
/**
* This method returns the area of Cylinder.
* @return 2 *(( Math.PI*Math.sqrt(r) )+( 2*Math.PI*r*getHeight() ));
*/
double E(){
// E = 2 * E(Βάσης) + Ε(Καμπήλης)
return 2 *(( Math.PI*Math.sqrt(r) )+( 2*Math.PI*r*getHeight() ));
}
/**
* This method returns the volume of Cylinder.
* @return Math.PI*Math.sqrt(r)*getHeight();
*/
double V(){
return Math.PI*Math.sqrt(r)*getHeight();
}
/**
* This method prints the dimensions of Cylinder.
*/
void show() {
System.out.println("R is: " + r + "\nHeight is: " + getHeight() + "\n");
}
}
/**
* This class demonstrates the methods of the Cube class.
* @author Ioannis Tzeneralis
* @version 1.0
*/
class Cube extends ThreeDShape {
/**
* Default constructor.
* @param x The width or Hight or Depth
*/
Cube(double x){
super(x);
}
/**
* Parameterized constructor.
* @param x The Width
* @param y The Hight
* @param z The Depth
*/
Cube(double x, double y, double z){
super(x, y, z);
}
/**
* This method returns the area of Cube.
* @return 6*Math.sqrt(getHeight());
* @return 2*(getWidth()+getDepth())*getHeight();
*/
double E(){
if (getHeight()==getWidth()){
return 6*Math.sqrt(getHeight());
}else{
return 2*(getWidth()+getDepth())*getHeight();
}
}
/**
* This method returns the volume of Cube.
* @return Math.sqrt(getHeight())*getHeight();
* @return 2*(getWidth()*getDepth()+getWidth()*getHeight()+getDepth()*getHeight());
*/
double V(){
if (getHeight()==getWidth()){
return Math.sqrt(getHeight())*getHeight();
}else{
return 2*(getWidth()*getDepth()+getWidth()*getHeight()+getDepth()*getHeight());
}
}
/**
* This method prints the dimensions of Cube.
*/
void show() {
if (getHeight()==getWidth()){
System.out.println("All sides of Cube are: " + getHeight() + "\n");
}else{
System.out.println("Width is: " + getWidth() + "\nHeight is: " + getHeight() + "\nDepth is: " + getDepth());
}
}
}
/**
* This class demonstrates the methods of the parallelepiped class.
* @author Ioannis Tzeneralis
* @version 1.0
*/
class parallelepiped extends ThreeDShape {
/**
* Default constructor.
* @param x The Width
* @param y The Hight
* @param z The Depth
*/
parallelepiped(double x, double y, double z){
super(x, y, z);
}
/**
* This method returns the area of parallelepiped.
* @return 2*(getWidth()*getHeight())+2*(getDepth()*getHeight())+2*(getWidth()*getDepth());
*/
double E(){
return 2*(getWidth()*getHeight())+2*(getDepth()*getHeight())+2*(getWidth()*getDepth());
}
/**
* This method returns the volume of parallelepiped.
* @return (getWidth()*getDepth())*getHeight();
*/
double V(){
return (getWidth()*getDepth())*getHeight();
}
/**
* This method prints the dimensions of parallelepiped.
*/
void show() {
System.out.println("Width is: " + getWidth() + "\nHeight is: " + getHeight() + "\nDepth is: " + getDepth());
}
}