image provider

Units of Measure


This essay does not describe an existing computer program, just one that should exist. This essay is about a suggested student project in Java programming. This essay gives a rough overview of how it might work. I have no source, object, specifications, file layouts or anything else useful to implementing this project. Everything I have prepared to help you is right here.

This project outline is not like the artificial, tidy little problems you are spoon-fed in school, when all the facts you need are included, nothing extraneous is mentioned, the answer is fully specified, along with hints to nudge you toward a single expected canonical solution. This project is much more like the real world of messy problems where it is up to you to fully the define the end point, or a series of ever more difficult versions of this project and research the information yourself to solve them.

Everything I have to say to help you with this project is written below. I am not prepared to help you implement it; or give you any additional materials. I have too many other projects of my own.

Though I am a programmer by profession, I don’t do people’s homework for them. That just robs them of an education.

You have my full permission to implement this project in any way you please and to keep all the profits from your endeavour.

Please do not email me about this project without reading the disclaimer above.

This project is similar to the currency converter, except instead of allowing you to localise a web page to the user’s preferred currency, it allows you to localise it to the user’s preferred units of measure, e.g. grams/kilograms vs ounces/pounds or cm/metres vs inches/feet.

For each country code you need a table of the units of measure they use. You also need a table of conversion factors. You can embed static macros in the HTML (Hypertext Markup Language) source code like this:

The rabbit was enormous weighing <!-- macro Dim 10.0 pounds -->. It had ears <!-- macro Dim 15.0 cm --> long!

You expand these to Applet invocations.

To a person from the USA, this would finally display as:

The rabbit was enormous weighing 10 pounds. It had ears 6 inches long!

To a person from Canada, this would finally display as:

The rabbit was enormous weighing 4.5 kilograms. It had ears 15 cm long!

You display to approximately the same degree of precision as the original.

Design your program as an Applet much like CurrCon, with a separate class to do the conversions, so that others can use the conversion logic in their own applications and Servlets. You might also implement it as some sort of JSP (Java Server Pages) tag for effortless inclusion into Servlets that generate web pages without Applet calls.

I have done a crude version of this with that expands to both metric and Imperial, igoring the viewer’s country.

The rabbit was enormous weighing <!-- macro Dim 10.0 pounds -->. It had ears <!-- macro Dim 15.0 cm --> long!

then expands as:

The rabbit was enormous weighing 4.54 kg (10 lbs). It had ears 15 cm (5.91 in) long!

For extra brownie points, see if you can translate this into metric:

A 3 mpg increase in the auto and light truck fleet is worth 1,000,000 barrels of oil a day.
~ Ernest J. Moniz (born:1944 age:72), Professor of Physics
In metric you use liters/100km (which is lower with better mileage, whereas mpg is higher with better mileage). Further, you have the complication of a delta versus an absolute value.

Temperature has to be handled specially, since it is not a simple multiplier. My static macro works like this:

<!-- macro Degrees 20 C -->

expands to:

20°C (68°F)


<!-- macro Degrees 10 F delta -->

expands to:

5.6°C (10.0°F)

to convert temperature changes to both Celsius/Centigrade and Fahrenheit.

As in CurrCon, you guess the default country using Locale. getDefault(). getCountry(); You allow the user to override the guess. That change gets propagated to all the Applets on the page, just as with CurrCon. Find the other instance of the Applet with getAppletContext(). getApplets().

Learning More

Oracle’s Miscellaneous documentation on @m annotation to ensure consistency of units of measure
acquiring CurrCon
CurrCon implementation
units of measure

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number