I am making a weather app that involves temperatures. You can change between Kelvin, Celsius, and Fahrenheit just for fun.
However, temperature figures get used all over the place in different ways. Does it make sense to have a Temperature class that stores the number as well as its units, and has various methods for internally converting it to some other unit of measurement, so I am not performing conversion math all over the place?
What is the accepted practice for storing its current state? A String? If currentUnits is "Fahrenheit" then do this, etc. Is there a better way to store these using enums or constants somehow?
Just trying to get a feel for the best practices here.
EDIT using weight instead:
public class Weight {
private double mWeight; // assumed to be in lbs
public Weight(double weight) {
mWeight = weight;
}
public double getWeight(Context context) {
AppSettings appsettings = new AppSettings(context);
if (appsettings.getUnitsPref().equals("kgs")){
mWeight *= 2.20462;
}
return mWeight;
}
}