-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyramid.java
More file actions
119 lines (84 loc) · 2.46 KB
/
Copy pathPyramid.java
File metadata and controls
119 lines (84 loc) · 2.46 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pyramidcalculator;
/**
* Create a pyramid and manipulate its properties.
* @author leandroestevez
*/
public class Pyramid {
private double baseWidth;
private double height;
/**
* Constructs a default pyramid.
*/
public Pyramid() {
baseWidth = 50;
height = 100;
}
/**
* Constructs a pyramid with a specific width and height.
* @param baseWidth width of the base.
* @param height height of the pyramid.
*/
public Pyramid(double baseWidth, double height) {
this.baseWidth = baseWidth;
this.height = height;
}
/**
* Calculates the volume of the pyramid.
* @return the volume of the pyramid.
*/
public double volume() {
double volume;
volume = (Math.pow(baseWidth, 2) * height)/3;
return volume;
}
/**
* Calculates the surface area of the pyramid.
* @return the surface area of the pyramid.
*/
public double surfaceArea() {
double surfaceArea;
surfaceArea = 2 * baseWidth * calculateS() + Math.pow(baseWidth, 2);
return surfaceArea;
}
/**
* Calculates the S of the pyramid.
* @return the S of the pyramid.
*/
private double calculateS() {
double s = Math.sqrt(Math.pow(baseWidth/2, 2) + Math.pow(height, 2));
return s;
}
/**
* Sets the base width of the pyramid.
* @param baseWidth base width of the pyramid.
*/
public void setBaseWidth(double baseWidth) {
this.baseWidth = baseWidth;
}
/**
* Sets the height of the pyramid.
* @param height height of the pyramid.
*/
public void setHeight(double height) {
this.height = height;
}
/**
* Gets the base width of the pyramid.
* @return the base width of the pyramid
*/
public double getBaseWidth() {
return baseWidth;
}
/**
* Gets the height of the pyramid.
* @return the height of the pyramid
*/
public double getHeight() {
return height;
}
}