summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-21 15:23:17 -0400
committerAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-21 15:23:17 -0400
commitce7402fb5e52d947b6b7c383fa96e3aaaf9da188 (patch)
treea036180832095671027babc8b0fc16e3ca4eca47
parent1bf43ad95e70019a69e91e09ff74f677082ed6f5 (diff)
Added back Fahrenheit, with more Imperial/USC units to come.
-rw-r--r--src/org/unitConverter/converterGUI/UnitConverterGUI.java3
-rw-r--r--src/org/unitConverter/unit/BritishImperial.java28
-rw-r--r--src/org/unitConverter/unit/USCustomary.java27
-rw-r--r--unitsfile.txt4
4 files changed, 59 insertions, 3 deletions
diff --git a/src/org/unitConverter/converterGUI/UnitConverterGUI.java b/src/org/unitConverter/converterGUI/UnitConverterGUI.java
index 511e47b..0be6c9b 100644
--- a/src/org/unitConverter/converterGUI/UnitConverterGUI.java
+++ b/src/org/unitConverter/converterGUI/UnitConverterGUI.java
@@ -44,6 +44,7 @@ import javax.swing.JTextField;
import org.unitConverter.math.ObjectProduct;
import org.unitConverter.unit.BaseDimension;
+import org.unitConverter.unit.BritishImperial;
import org.unitConverter.unit.LinearUnit;
import org.unitConverter.unit.SI;
import org.unitConverter.unit.Unit;
@@ -78,7 +79,7 @@ final class UnitConverterGUI {
database.addUnit("unit", SI.ONE);
// nonlinear units - must be loaded manually
database.addUnit("tempCelsius", SI.CELSIUS);
- // database.addUnit("tempFahrenheit", NonlinearUnits.FAHRENHEIT);
+ database.addUnit("tempFahrenheit", BritishImperial.FAHRENHEIT);
// load initial dimensions
database.addDimension("LENGTH", SI.Dimensions.LENGTH);
diff --git a/src/org/unitConverter/unit/BritishImperial.java b/src/org/unitConverter/unit/BritishImperial.java
new file mode 100644
index 0000000..c9316f3
--- /dev/null
+++ b/src/org/unitConverter/unit/BritishImperial.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright (C) 2019 Adrien Hopkins
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package org.unitConverter.unit;
+
+/**
+ * A static utility class that contains units in the British Imperial system.
+ *
+ * @author Adrien Hopkins
+ * @since 2019-10-21
+ */
+public final class BritishImperial {
+ public static final Unit FAHRENHEIT = Unit.fromConversionFunctions(SI.KELVIN.getBase(),
+ tempK -> tempK * 1.8 - 459.67, tempF -> (tempF + 459.67) / 1.8);
+}
diff --git a/src/org/unitConverter/unit/USCustomary.java b/src/org/unitConverter/unit/USCustomary.java
new file mode 100644
index 0000000..f5f9a7f
--- /dev/null
+++ b/src/org/unitConverter/unit/USCustomary.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright (C) 2019 Adrien Hopkins
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package org.unitConverter.unit;
+
+/**
+ * A static utility class that contains units in the US Customary system.
+ *
+ * @author Adrien Hopkins
+ * @since 2019-10-21
+ */
+public final class USCustomary {
+ public static final Unit FAHRENHEIT = BritishImperial.FAHRENHEIT;
+}
diff --git a/unitsfile.txt b/unitsfile.txt
index 73a29d1..bda9b81 100644
--- a/unitsfile.txt
+++ b/unitsfile.txt
@@ -146,9 +146,9 @@ deg degree
# Use tempC(100) for 100 degrees Celsius
tempCelsius !
-#tempFahrenheit !
+tempFahrenheit !
tempC tempCelsius
-#tempF tempFahrenheit
+tempF tempFahrenheit
# Common time units
minute 60 second