Body Mass Index Calculator App) The formulas for calculating the BMI are BMI =(w
ID: 3814594 • Letter: B
Question
Body Mass Index Calculator App) The formulas for calculating the BMI are
BMI =(weightInPounds × 703) /(heightInInches × heightInInches) or
BMI=( weightInKilograms)/(heightInMeters × heightInMeters)
Create a BMI calculator app that allows users to enter their weight and height and whether they are entering these values in English or metric units, then calculates and displays the user’s body mass index. The app should also display the following information from the Department of Health and Human Services/National Institutes of Health so that users can evaluate their BMIs:
BMI VALUES
Underweight: less than 18.5
Normal: between 18.5 and 24.9
Overweight: between 25 and 29.9
Obese: 30 or greater
must implement javaFX using netbean with BMI.java, BMIController.java and BMI.xml. i tried one solution before too but gave too many errors. is it possible to post the output too?
Explanation / Answer
GUI for Body Mass index
===================
import javax.swing.JFrame;
public class BMI
{
public static void main (String[] args)
{
private int WIDTH = 300;
private int HEIGHT = 120;
JFrame frame = new JFrame("BMI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BMIGUI panel = new BMIGUI();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
frame.setSize(WIDTH, HEIGHT);
}
==================================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class BMIGUI extends JPanel
{
private JLabel heightLabel, weightLabel, BMILabel, resultLabel;
private JTextField height, weight;
private JButton calculate;
public BMIGUI()
{
heightLabel = new JLabel ("height in in.:");
weightLabel = new JLabel ("weight in lbs: ");
BMILabel = new JLabel ("your BMI:");
resultLabel = new JLabel ("result:");
height = new JTextField ();
weight = new JTextField ();
calculate = new JButton ("Begin");
BMIListener Listener = new BMIListener();
calculate.addActionListener(Listener);
setPreferredSize (new Dimension(WIDTH, HEIGHT));
setBackground (Color.yellow);
frame.getContentPane().add(heightLabel);
frame.getContentPane().add(height);
frame.getContentPane().add(weightLabel);
frame.getContentPane().add(weight);
frame.getContentPane().add(calculate);
frame.getContentPane().add(BMILabel);
frame.getContentPane().add(resultLabel);
}
private class BMIListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
String heightText, weightText;
int heightVal, weightVal;
double bmi;
String respon1 = height.getText();
double t = Double.parseDouble(respon1);
String respon2 = weight.getText();
double v = Double.parseDouble(respon2);
bmi = (703 * weightVal / (heightVal * heightVal));
String str = String.valueof(bmi);
resultLabel.setText(str);
}
}
}