Question 5: The formulae for calculating Body Mass Index (BMI) are BMI = (weight
ID: 3679432 • Letter: Q
Question
Question 5: The formulae for calculating Body Mass Index (BMI) are BMI = (weight in pounds x 703) / (height in Inches x height in Inches) Or BMI = (weight in Kilograms) / (height in Meters x height in Meters) Create a BMI calculator app that reads the user’s weight in pounds and height in inches (or, if you prefer, the user’s weight in Kilograms and height in Meters), then calculates and displays the user’s body mass index. Also, the app should use a multiline TextBox with its Enabled Property set to False and its Font property set to Lucinda console to display the following information from the Department of Health and Human Services/National Institute of Health so the user can evaluate his/her BMI. BMI Values: Underweight: less than 18.5 Normal: between 18.5 and 24.9 Overweight: between 25 and 29.9 Obese: 30 or greater.
Explanation / Answer
import javax.swing.*;
import java.awt.event.*;
class BMI implements ActionListener
{
//Declare java frame,textfield,textarea,button and label
JFrame f;
JTextField height,weight;
JTextArea info;
JButton calculate;
Jlabel mybmi;
static double h=0,w=0,result;
BMI()
{
//initialuze jfram components and add them to the frame
f=new JFrame("Calculator");
t=new JTextField();
f.add(height);
f.add(weight);
f.add(calculate);
//add action listener to the button
calculate.addActionListener(this);
f.add(mybmi);
f.add(info);
//set font and editable property for the text area
Font font = new Font(“Lucinda”,Font.BOLD,12);
Info.setFont(font);
Info.setText(“UnderWeight: less than 18.5 Normal: between 18.5 and 24.9 Overweight: between 25 and 29.9 Obese: 30 or greater.”);
Info.setEditable(False);
f.setVisible(true);
}
//implement action performed for the button
Public void actionPerformed(ActionEvent e)
{
h=Double.parseDouble(height.getText());
w=Double.parseDouble(weight.getText());
result = h/w;
//set result to the label
mybmi.setText(“your bmi: “+result);
}
Public static void main(String args[])
{
//call class constructor
new BMI();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.