make the Unit Class enums
This commit is contained in:
parent
f5eed945a2
commit
a83885745c
1 changed files with 13 additions and 28 deletions
|
|
@ -1,47 +1,32 @@
|
||||||
package commons;
|
package commons;
|
||||||
|
|
||||||
//what is a record class and why is it recommended
|
//what is a record class and why is it recommended
|
||||||
public final class Unit {
|
public enum Unit {
|
||||||
|
|
||||||
|
|
||||||
//stupid magic numbers
|
|
||||||
private static final double GRAMS = 1.0;
|
|
||||||
private static final double KILOGRAMS = 1000.0;
|
|
||||||
private static final double MILLILITERS = 1.0;
|
|
||||||
private static final double LITERS = 1000.0;
|
|
||||||
private static final double TABLESPOONS = 15.0;
|
|
||||||
private static final double TEASPOONS = 5.0;
|
|
||||||
private static final double CUPS = 240.0;
|
|
||||||
private static final double PIECES = 1.0;
|
|
||||||
|
|
||||||
private static final double NoMeaningfulValue = 0.0;
|
|
||||||
|
|
||||||
|
|
||||||
//formal units
|
//formal units
|
||||||
//weight units
|
//weight units
|
||||||
public static final Unit GRAM = new Unit("GRAM", true, GRAMS);
|
GRAM("GRAM", true, 1.0),
|
||||||
public static final Unit KILOGRAM = new Unit("KILOGRAM", true, KILOGRAMS );
|
KILOGRAM("KILOGRAM", true, 1000.0 ),
|
||||||
|
|
||||||
//volume units
|
//volume units
|
||||||
public static final Unit MILLILITER = new Unit("MILLILITER",true, MILLILITERS);
|
MILLILITER("MILLILITER",true, 1.0),
|
||||||
public static final Unit LITER = new Unit("LITER", true, LITERS);
|
LITER("LITER", true, 1000.0),
|
||||||
public static final Unit TABLESPOON = new Unit("TABLESPOON",true, TABLESPOONS);
|
TABLESPOON("TABLESPOON",true, 15.0),
|
||||||
public static final Unit TEASPOON = new Unit("TEASPOON", true, TEASPOONS);
|
TEASPOON("TEASPOON", true, 5),
|
||||||
public static final Unit CUP = new Unit("CUP", true, CUPS);
|
CUP ("CUP", true, 240.0),
|
||||||
|
|
||||||
//piece should be a formal unit to converse for portions like 3eggs can become 1,5 eggs this way
|
//piece should be a formal unit to converse for portions like 3eggs can become 1,5 eggs this way
|
||||||
public static final Unit PIECE = new Unit("PIECE", true, PIECES);
|
PIECE("PIECE", true, 1.0),
|
||||||
|
|
||||||
//informal units
|
//informal units
|
||||||
public static final Unit PINCH = new Unit("PINCH", false, NoMeaningfulValue);
|
PINCH("PINCH", false, 0.0),
|
||||||
public static final Unit HANDFUL = new Unit("HANDFUL", false, NoMeaningfulValue);
|
HANDFUL("HANDFUL", false, 0.0),
|
||||||
public static final Unit TO_TASTE = new Unit("TO_TASTE", false, NoMeaningfulValue);
|
TO_TASTE("TO_TASTE", false, 0.0);
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public final boolean formal;
|
public final boolean formal;
|
||||||
public final double conversionFactor;
|
public final double conversionFactor;
|
||||||
|
|
||||||
private Unit(String name, boolean formal, double conversionFactor) {
|
Unit(String name, boolean formal, double conversionFactor) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.formal = formal;
|
this.formal = formal;
|
||||||
this.conversionFactor = conversionFactor;
|
this.conversionFactor = conversionFactor;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue