How to implement a unit converter in java

Posted by Mohit Deshpande on Stack Overflow See other posts from Stack Overflow or by Mohit Deshpande
Published on 2010-05-21T23:18:59Z Indexed on 2010/05/21 23:20 UTC
Read the original article Hit count: 167

Filed under:
|

How could I possibly implement a unit converter in Java??? I was thinking of having a abstract base class:

public abstract class Unit
{
    ...
    public void ConvertTo(Unit unit);
}

Then having each class like Meter Kilometer Inch Centimeter Millimeter ... derive from that base Unit class. All the units of length would be in a package called com.unitconverter.distance, then a package, com.unitconverter.energy, for energy etc. etc. So is this the best way to implement a unit converter? Or is there a better or more easier way?

© Stack Overflow or respective owner

Related posts about java

Related posts about abstract-class