-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnitConverter.java
More file actions
40 lines (30 loc) · 1.14 KB
/
UnitConverter.java
File metadata and controls
40 lines (30 loc) · 1.14 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
public class UnitConverter {
public static int celsius = 0;
public static int fahrenheit = 0;
public static final double KILOGRAMS_PER_POUND = 0.45359237;
public static final double POUNDS_PER_KILOGRAM = 1 / KILOGRAMS_PER_POUND;
public static final double CENTIMETERS_PER_INCH = 2.54;
public static final double INCHES_PER_CENTIMETER = 1 / CENTIMETERS_PER_INCH;
public static final double CELSIUS_PER_FAHRENHEIT = 0;
public static final double FAHRENHEIT_PER_CELSIUS = 0;
public static double toPounds(double kilograms) {
return POUNDS_PER_KILOGRAM * kilograms;
}
public static double toKilograms(double pounds) {
return KILOGRAMS_PER_POUND * pounds;
}
public static double toCentimeters(double inches) {
return CENTIMETERS_PER_INCH * inches;
}
public static double toInches(double centimeters) {
return INCHES_PER_CENTIMETER * centimeters;
}
//
public static double toFahrenheit(double celsius) {
return (celsius * 9/5) + 32;
}
//
public static double toCelsius(double fahrenheit) {
return (fahrenheit - 32) / 1.8;
}
}