FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/Maths/Area.java at master · ppdouble/Java · GitHub
ppdouble
/
Java
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
Maths
/
Area.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
117 lines (100 loc) · 3.03 KB
Breadcrumbs
Java
/
Maths
/
Area.java
Copy path
File metadata and controls
117 lines (100 loc) · 3.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
Maths
;
/** Find the area of various geometric shapes */
public
class
Area
{
public
static
void
main
(
String
[]
args
) {
/* test cube */
assert
Double
.
compare
(
surfaceAreaCube
(
1
),
6.0
) ==
0
;
/* test sphere */
assert
Double
.
compare
(
surfaceAreaSphere
(
5
),
314.1592653589793
) ==
0
;
assert
Double
.
compare
(
surfaceAreaSphere
(
1
),
12.566370614359172
) ==
0
;
/* test rectangle */
assert
Double
.
compare
(
surfaceAreaRectangle
(
10
,
20
),
200.0
) ==
0
;
/* test square */
assert
Double
.
compare
(
surfaceAreaSquare
(
10
),
100.0
) ==
0
;
/* test triangle */
assert
Double
.
compare
(
surfaceAreaTriangle
(
10
,
10
),
50.0
) ==
0
;
/* test parallelogram */
assert
Double
.
compare
(
surfaceAreaParallelogram
(
10
,
20
),
200.0
) ==
0
;
/* test trapezium */
assert
Double
.
compare
(
surfaceAreaTrapezium
(
10
,
20
,
30
),
450.0
) ==
0
;
/* test circle */
assert
Double
.
compare
(
surfaceAreaCircle
(
20
),
1256.6370614359173
) ==
0
;
}
/**
* Calculate the surface area of a cube.
*
* @param sideLength side length of cube
* @return surface area of given cube
*/
private
static
double
surfaceAreaCube
(
double
sideLength
) {
return
6
*
sideLength
*
sideLength
;
}
/**
* Calculate the surface area of a sphere.
*
* @param radius radius of sphere
* @return surface area of given sphere
*/
private
static
double
surfaceAreaSphere
(
double
radius
) {
return
4
*
Math
.
PI
*
radius
*
radius
;
}
/**
* Calculate the area of a rectangle
*
* @param length length of rectangle
* @param width width of rectangle
* @return area of given rectangle
*/
private
static
double
surfaceAreaRectangle
(
double
length
,
double
width
) {
return
length
*
width
;
}
/**
* Calculate the area of a square
*
* @param sideLength side length of square
* @return area of given square
*/
private
static
double
surfaceAreaSquare
(
double
sideLength
) {
return
sideLength
*
sideLength
;
}
/**
* Calculate the area of a triangle
*
* @param base base of triangle
* @param height height of triangle
* @return area of given triangle
*/
private
static
double
surfaceAreaTriangle
(
double
base
,
double
height
) {
return
base
*
height
/
2
;
}
/**
* Calculate the area of a parallelogram
*
* @param base base of parallelogram
* @param height height of parallelogram
* @return area of given parallelogram
*/
private
static
double
surfaceAreaParallelogram
(
double
base
,
double
height
) {
return
base
*
height
;
}
/**
* Calculate the area of a trapezium
*
* @param base1 upper base of trapezium
* @param base2 bottom base of trapezium
* @param height height of trapezium
* @return area of given trapezium
*/
private
static
double
surfaceAreaTrapezium
(
double
base1
,
double
base2
,
double
height
) {
return
(
base1
+
base2
) *
height
/
2
;
}
/**
* Calculate the area of a circle
*
* @param radius radius of circle
* @return area of given circle
*/
private
static
double
surfaceAreaCircle
(
double
radius
) {
return
Math
.
PI
*
radius
*
radius
;
}
}
Back
|
FazBrowse Home
|
New Git URL