Re: How should I do this?
The first thing that pops into my head is to have a Map<Unit, Map<Unit, Conversion>> data structure where Unit is an enum of all the different types of units, and Conversion is an interface that basically takes one Unit and converts it to another.
So you'd have something like:
Code java:
conversionMap.get(Unit.INCHES).put(Unit.FEET, new Conversion(){public void convert(double inches){return inches/12;}});
So then to convert from inches to feet you'd do:
Code java:
double feet = conversionMap.get(Unit.INCHES).get(Unit.FEET).convert(inches);
Anyway, that's just the first thing I thought of, so there are probably better ways.
Re: How should I do this?
I would still have to use 1,849 statements for this though...I don't want to have to copy + paste + change slightly that many times.
Re: How should I do this?
Haha, well, I'm not sure there's a better way, since there is no automatic way to know the conversions. You're going to have to write quite a bit of code for 43 X 43 conversions, so you might want to start off smaller and add to it as you go.
And, you would not have to write 1,849 statements, as not every unit converts to every other unit.
Re: How should I do this?
If you have the units specified in some sort of parsable format, then rather than manually hard coding each, you could write a script which prints out to the command line those values in the form of the source code you need - which you can then just copy and paste into your class.