I do contract work for a living, which could include writing a program such as this. However, 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 any way you please.
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 source code like this:
The rabbit was enormous weighing <!-- macro Measure 10.0 pounds -->. It had ears <!-- macro Measure 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 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 Measure 10.0 pounds -->. It had ears <!-- macro Measure 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.”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.
~ Ernest Moniz, Professor of Physics, born 1938
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)
where
<!-- macro Degrees 10 F delta -->
expands to:
6°C (10°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().
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.61] | ![]() | ||
| You are visitor number 11. | |||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | ||
| http://mindprod.com/project/unitsofmeasure.html | J:\mindprod\project\unitsofmeasure.html | ||