forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathUtil.java
More file actions
39 lines (33 loc) · 1.07 KB
/
MathUtil.java
File metadata and controls
39 lines (33 loc) · 1.07 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
public class MathUtil
{
public static double getCargoVolume(double height, double length, double depth, boolean heavyDuty)
{
double thickness = 0.25;
if (heavyDuty)
thickness *= 2;
double volume = (height - 2 * thickness) * (length - 2 * thickness) * (depth - 2 * thickness);
return volume;
}
public static int getTotal(int firstNumber, int secondNumber)
{
int sum = firstNumber + secondNumber;
return sum;
}
public static int absoluteSum(int first, int second)
{
int sum = Math.abs(first) + Math.abs(second);
return sum;
}
public static int absoluteSum(int first, int second, int third)
{
int sum = Math.abs(first) + Math.abs(second) + Math.abs(third);
return sum;
}
public static void main(String[] args)
{
System.out.println(getTotal(12, 12));
System.out.println(getCargoVolume(10.5, 12.5, 15.5, false));
System.out.println(absoluteSum(12, -12));
System.out.println(absoluteSum(12, -12, -12));
}
}