Question

In: Computer Science

ONLY IN JAVAFX. The application will calculate Body Mass Index (BMI) for people. It must be...

ONLY IN JAVAFX. The application will calculate Body Mass Index (BMI) for people. It must be able to accept as input weights (in pounds or kilos), and height (in inches or centimeters). The application should have a calculate button, and should display the result as well as if the data puts the person in one of 4 categories underweight ( BMI < 18.5) , normal weight (BMI 18.5-24.9), overweight (BMI 25.0 - 29.9) or overweight (BMI > 30)

Solutions

Expert Solution

BMIController.java

package bmi;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

public class BMIController implements Initializable {
  
@FXML
private Label label;
@FXML
private RadioButton pi;
@FXML
private RadioButton km;
@FXML
private TextField weight;
@FXML
private TextField height;
  
  
  
@FXML
private void handleButtonAction(ActionEvent event) {
try{
Double w = new Double(weight.getText());
Double h = new Double(height.getText());
Double bmi;
  
if(pi.isSelected()){
bmi = (w * 703.0)/(h*h);
label.setText(String.format("%.2f",bmi));
}
else if(km.isSelected()) {
bmi = w /(h*h);
label.setText(String.format("%.2f",bmi));
}
  
}catch(NumberFormatException nf){
weight.setText("Enter valid value");
weight.selectAll();
weight.requestFocus();
height.setText("Enter valid value");
height.selectAll();
  
}
  
}
  
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
  
}

BMI.java

package bmi;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class BMI extends Application {
  
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("BMI.fxml"));
  
Scene scene = new Scene(root);
stage.setTitle("BMI CALCULATOR");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch(args);
}
  
}

BMI.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="480.0" prefWidth="412.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="bmi.BMIController">
<children>
<Button fx:id="button" layoutX="155.0" layoutY="272.0" onAction="#handleButtonAction" text="Calculate" />
<Label fx:id="label" alignment="CENTER" layoutX="14.0" layoutY="381.0" minHeight="16" minWidth="69" prefHeight="64.0" prefWidth="180.0" text="0.0">
<font>
<Font name="System Bold Italic" size="24.0" />
</font></Label>
<TextArea layoutX="193.0" layoutY="319.0" prefHeight="147.0" prefWidth="206.0" text="BMI VALUES&#10;Underweight:&#9;less than 18.5&#10;Normal:&#9;&#9;between 18.5 and 24.9&#10;Overweight:&#9;between 25 and 29.9&#10;Obese:&#9;&#9;30 or greater&#10;">
<font>
<Font size="11.0" />
</font>
</TextArea>
<TextField fx:id="weight" layoutX="110.0" layoutY="145.0" />
<TextField fx:id="height" layoutX="110.0" layoutY="213.0" />
<RadioButton fx:id="pi" layoutX="60.0" layoutY="47.0" mnemonicParsing="false" selected="true" text="Pounds-Inches">
<toggleGroup>
<ToggleGroup fx:id="ip" />
</toggleGroup>
</RadioButton>
<RadioButton fx:id="km" layoutX="227.0" layoutY="47.0" mnemonicParsing="false" text="Kilograms-Meters" toggleGroup="$ip" />
<Label layoutX="119.0" layoutY="117.0" text="Weight" />
<Label layoutX="119.0" layoutY="190.0" text="Height" />
<Label layoutX="28.0" layoutY="319.0" prefHeight="50.0" prefWidth="152.0" text="Your BMI is:">
<font>
<Font size="24.0" />
</font>
</Label>
</children>
</AnchorPane>


Related Solutions

1. BMI or body mass index is a way to classify people according to their height...
1. BMI or body mass index is a way to classify people according to their height and weight. For all state employees, the state of North Carolina is making everyone who has a BMI greater than 30 pay extra for their health insurance. Assume that BMI is approximately a normal distribution with a mean of 27.73 and a standard deviation of 6.10 . a. What percent of the state employees would have to pay extra for health insurance? b. Suppose...
Discuss the process of calculating Body Mass Index (BMI).
Discuss the process of calculating Body Mass Index (BMI).
The body mass index​ (BMI) for a sample of men and a sample of women are...
The body mass index​ (BMI) for a sample of men and a sample of women are given below. Assume the samples are simple random samples obtained from populations with normal distributions. Men 30.930.9 22.322.3 29.929.9 30.930.9 27.227.2 31.731.7 26.526.5 20.220.2 26.626.6 30.530.5 Women nbspWomen 18.218.2 20.720.7 22.222.2 28.428.4 17.117.1 20.320.3 23.923.9 31.831.8 20.820.8 20.720.7 LOADING... Click the icon to view the table of​ Chi-Square critical values. a. Construct aa 9090​% confidence interval estimate of the standard deviation of BMIs for...
Design a modular program that calculates and displays a person's body mass index (BMI). The BMI...
Design a modular program that calculates and displays a person's body mass index (BMI). The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height. A person's BMI is calculated with the following formula: BMI=Weight*703/Height^2. I need help making this to Java to just calculate BMI.
Body mass index (BMI) is a reliable indicator of body fat for most children and teens....
Body mass index (BMI) is a reliable indicator of body fat for most children and teens. BMI is calculated from a child’s weight and height and is used as an easy-to-perform method of screening for weight categories that may lead to health problems. For children and teens, BMI is age- and sex-specific and is often referred to as BMI-for-age. The Centers for Disease Control and Prevention (CDC) reports BMI-for-age growth charts for girls as well as boys to obtain a...
We claim that the body mass index (BMI) for men is statistically the same as the...
We claim that the body mass index (BMI) for men is statistically the same as the BMI for women. Data from a random sample of 40 men and 40 women is presented below: BMI-M BMI-F Mean 25.9975 Mean 25.74 Standard Error 0.542448 Standard Error 0.974862 Median 26.2 Median 23.9 Mode 23.8 Mode 19.6 Standard Deviation 3.430742 Standard Deviation 6.16557 Sample Variance 11.76999 Sample Variance 38.01426 Kurtosis -0.13645 Kurtosis 1.517743 Skewness 0.356785 Skewness 1.189501 Range 13.6 Range 27.2 Minimum 19.6 Minimum...
The data file contains the Body Mass Index (BMI) for a sample of men and a...
The data file contains the Body Mass Index (BMI) for a sample of men and a sample of women. Two of the columns, OW_male and OW_female code the BMI values as: 0 - if BMI ≤ 25.4 (these are considered “not overweight”); 1 - if BMI >= 25.5 (these are considered “overweight”). (a) Test whether there is sufficient evidence to show that the proportion of overweight males (proportion of males who are overweight) is different than the proportion of overweight...
If a regression analysis was to be completed on body mass index (BMI), what could be...
If a regression analysis was to be completed on body mass index (BMI), what could be an independent variable in that analysis? Why? If we could, what other independent variables should be included in the analysis? What statistic(s) would show the value of that regression in understanding BMI? Alternatively, find an article that uses regression analysis to study a medical concern. In that study, what was the dependent variable and what was the independent variable(s)? Further, how would you use...
The Body Mass Index (BMI) is a value calculated based on the weight and the height...
The Body Mass Index (BMI) is a value calculated based on the weight and the height of an individual. In a small European city, a survey was conducted one year ago to review the BMI of the citizens. In the sample 22 with 200 citizens, the mean BMI was 23.3 kg/m and standard deviation was 1.5 kg/m . It is reasonable to assume the BMI distribution is a normal distribution. (a) Find the point estimate of the population mean BMI...
The Body Mass Index (BMI) is a value calculated based on the weight and the height...
The Body Mass Index (BMI) is a value calculated based on the weight and the height of an individual. In a small European city, a survey was conducted one year ago to review the BMI of the citizens. In the sample with 200 citizens, the mean BMI was 23.3 kg/m2 and standard deviation was 1.5 kg/m2 . It is reasonable to assume the BMI distribution is a normal distribution. (a) Find the point estimate of the population mean BMI one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT