• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BMI calculator to automaticly convert units from metric to imperial

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,


I wrote a simple BMI calc in NetBeans 15. (I used newjFrame form to design layout)

At the moment user can input values using either imperial or metric units (I have separate buttons for lbs and kg and for inches and cm).

I can choose witch units I want to use. So if I choose buttons "lbs" and "inch" I have to put imperial units.
If I choose "kg" and "cm" then metric (which is obvious).

But I want to modify program so it will automatically convert units from metric to imperial and vice versa.
Say I put weight in pounds and height in inches (buttons lbs and inch are selected) . What I want now is when I'll change buttons to kg and cm program should convert units from imperial to metric for me . Hope that makes sense


So after running program looks like that (See link bellow):




Main part of code ( I cut most of code generated by NetBeans so it will be easier to read)



Thank you all for any advice
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Mick,

welcome to the Ranch and enjoy the stay!

You can do for instance:

and likewise for the kg, inch and cm-radiobuttons.

As you have it now, these radiobuttons are only checked when the 'calculate'-button is clicked, so in the new situation the lbs-button may be clicked before the inputfields are filled, so in your actionListener, check whether all necessary fields are filled (or assume 0).    

Edit: oops. I forgot that in what I suggested, you may get the situation that lbs is selected, while cm is also selected. To remedy this, when lbs is selected, then first select the inch-button too, before invoking the calculate-method, and likewise for kg and cm. So, for instance:
 
Mick Boro
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your advice. I'll try to implement this into my program.
 
reply
    Bookmark Topic Watch Topic
  • New Topic