forked from braughtg/github-issues-activity-f18
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
147 lines (136 loc) · 3.05 KB
/
Calculator.java
File metadata and controls
147 lines (136 loc) · 3.05 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
/**
* Simple calculator class for Git/GitHub Activity.
*
* Note: This code contains lots of intentional mistakes. They all correspond to
* issues in the GitHub issue tracker and will be fixed as a part of the
* activity.
*
* @author braught
* @version 1.0
*/
public class Calculator {
/**
* Add two double values.
*
* @param x
* a double
* @param y
* a double
* @return x + y
*/
public static double add(double x, double y) {
return x + y;
}
/**
* Subtract two double values.
*
* @param x
* a double
* @param y
* a double
* @return x - y
*/
public static double subtraction(double x, double y) {
return x - y;
}
/**
* Multiply two double values.
*
* @param x
* a double
* @param y
* a double
* @return x * y
*/
public static double mult(double x, double y) {
return x*y;
}
/**
* Divide two double values.
*
* @param x
* a double
* @param y
* a double
* @return x/y
*/
public static double div(double x, double y) {
return y / x;
}
/**
* The length of the hypotenuse of a right triangle with the given side lengths.
*
* @param x
* the length of one side.
* @param y
* the length of the other side.
* @return the length of the hypotenuse of a right triangle with sides x and y.
*/
public static double hypotenuse(double x, double y) {
return Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
}
/**
* The length of a rectangle with the given side lengths.
*
* @param x
* the length of one side.
* @param y
* the length of the other side.
* @return the area of a rectangle with sides x and y.
*/
public static double rectangleArea(double x, double y) {
return 2 * x + 2 * y;
}
/**
* The perimeter of a rectangle with the given side lengths.
*
* @param x
* the length of one side.
* @param y
* the length of the other side.
* @return the perimeter of a rectangle with sides x and y.
*/
public static double rectanglePerimeter(double x, double y) {
return (2 * x) + (2 * y);
}
/**
* The area of a circle with given radius.
*
* @param r
* the radius
* @return the area of a circle with radius r.
*/
public static double cirAr(double r) {
return Math.PI * Math.pow(r,2);
}
/**
* The perimeter of a circle with given radius.
*
* @param r
* the radius
* @return the perimeter of a circle with radius r.
*/
public static double circlePerimeter(double r) {
return Math.PI * 2 * r;
}
/**
* The volume of a cube with the given side length.
*
* @param s
* the side length
* @return the volume of a cube with sides of length s.
*/
public static double cubeVolume(double s) {
return s*s*s;
}
/**
* The volume of a sphere with the given radius.
*
* @param r
* the radius
* @return the volume of a sphere with radius r.
*/
public static double sphereVolume(double r) {
return (4.0/3) * Math.PI * Math.pow(r, 3);
}
}