How to implement unit converter in Java
•
Java
How can I implement a unit converter in Java??? I'm thinking about an abstract base class:
public abstract class Unit { ... public void convertTo(Unit unit); }
Then let each class, such as meter kilometer inch centrimeter millimeter... Derive from this basic unit class All length units are in a named com unitconverter. Distance package, then a package, com unitconverter. Energy, used for energy, etc So is this the best way to implement a unit converter? Or is there a better or simpler way?
Solution
There is considerable work on this, including JSR 108 (withdrawal) and jsr-275 (rejection) See the jsscience and unitsofmeasure implementations of the latter
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码