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;
|
||||
|
||||
//what is a record class and why is it recommended
|
||||
public final class 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;
|
||||
|
||||
|
||||
public enum Unit {
|
||||
//formal units
|
||||
//weight units
|
||||
public static final Unit GRAM = new Unit("GRAM", true, GRAMS);
|
||||
public static final Unit KILOGRAM = new Unit("KILOGRAM", true, KILOGRAMS );
|
||||
GRAM("GRAM", true, 1.0),
|
||||
KILOGRAM("KILOGRAM", true, 1000.0 ),
|
||||
|
||||
//volume units
|
||||
public static final Unit MILLILITER = new Unit("MILLILITER",true, MILLILITERS);
|
||||
public static final Unit LITER = new Unit("LITER", true, LITERS);
|
||||
public static final Unit TABLESPOON = new Unit("TABLESPOON",true, TABLESPOONS);
|
||||
public static final Unit TEASPOON = new Unit("TEASPOON", true, TEASPOONS);
|
||||
public static final Unit CUP = new Unit("CUP", true, CUPS);
|
||||
MILLILITER("MILLILITER",true, 1.0),
|
||||
LITER("LITER", true, 1000.0),
|
||||
TABLESPOON("TABLESPOON",true, 15.0),
|
||||
TEASPOON("TEASPOON", true, 5),
|
||||
CUP ("CUP", true, 240.0),
|
||||
|
||||
//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
|
||||
public static final Unit PINCH = new Unit("PINCH", false, NoMeaningfulValue);
|
||||
public static final Unit HANDFUL = new Unit("HANDFUL", false, NoMeaningfulValue);
|
||||
public static final Unit TO_TASTE = new Unit("TO_TASTE", false, NoMeaningfulValue);
|
||||
PINCH("PINCH", false, 0.0),
|
||||
HANDFUL("HANDFUL", false, 0.0),
|
||||
TO_TASTE("TO_TASTE", false, 0.0);
|
||||
|
||||
public final String name;
|
||||
public final boolean formal;
|
||||
public final double conversionFactor;
|
||||
|
||||
private Unit(String name, boolean formal, double conversionFactor) {
|
||||
Unit(String name, boolean formal, double conversionFactor) {
|
||||
this.name = name;
|
||||
this.formal = formal;
|
||||
this.conversionFactor = conversionFactor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue