Question
javafx
1. Implement a BMI (Body Mass Index) server that will accept height and weight from the client, calculate the BMI and return
package module14lab; @author John Gerstenberg . public class BNI ( private String name; private int age; private double weigh
public String getName() { return name; ) public int getAge() { return age; 3 public double getweight() { return weight; 3 pub
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

First is the BMIcontroller and 2nd one is BMI class 3rd is BMI.fxml

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
}
  
}

Now BMI java class.

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();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
  
}

And now is BMIfxml.

<?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>

Add a comment
Know the answer?
Add Answer to:
javafx 1. Implement a BMI (Body Mass Index) server that will accept height and weight from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The body mass index (BMI) is a measure of relative weight based on height and weight....

    The body mass index (BMI) is a measure of relative weight based on height and weight. The body fat percentage (BFP) of a human or other living being is the total mass of fat divided by total body mass, multiplied by 100; body fat includes essential body fat and storage body fat. Essential body fat is necessary to maintain life and reproductive functions. Write a program that calculates and prints the BFP for multiple persons; the program allows user to...

  • IT Java code In Lab 8, we are going to re-write Lab 3 and add code...

    IT Java code In Lab 8, we are going to re-write Lab 3 and add code to validate user input. The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy level for a given height. The formula is as follows:                 bmi = kilograms / (meters2)                 where kilograms = person’s weight in kilograms, meters = person’s height in meters BMI is then categorized as follows: Classification BMI Range Underweight Less...

  • Body mass index (BMI) is computed as the ratio of the weight in kilograms to height...

    Body mass index (BMI) is computed as the ratio of the weight in kilograms to height in meters squared. The distribution of BMI is approximately normal for specific gender and age-groups. For females aged 30-39, the mean BMI is 24.5, with a standard deviation of 3.3. Suppose we classify females aged 30-39 in the top 10% of the BMI distribution as high risk of developing back pain. What is the threshold (minimum) BMI for classifying a female as high risk?

  • Using JAVAFX The application will calculate Body Mass Index (BMI) for people. It must be able...

    Using 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) For full credit...

  • 1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store...

    1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store the number of lives remaining: numLives – Write a constructor that initializes numLives to 9 and initializes name, age, & weight based on formal parameter values 2. Write a main method to test your Cat constructor & call the inherited writeOutput() method 3. Write a new writeOutput method in Cat that uses “super” to print the Cat’s name, age, weight & numLives – Does...

  • 1. Your Body Mass Index (BMI) is a measure of your weight relative to your height....

    1. Your Body Mass Index (BMI) is a measure of your weight relative to your height. The formula can be found here: http://www.whathealth.com/bmi/formula.html (use the Imperial U.S. Method). Write an algorithm in pseudocode to calculate and display a person's BMI accepting as input their height in feet and inches and their weight in pounds. The output of your algorithm should be as follows: a. BMI b. A statement of whether the result is underweight, normal, overweight or obese.

  • java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the...

    java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date {    private String month;    private String day;    private String year;    public Date(String month, String day, String year) {       this.month = month;       this.day = day;       this.year = year;    }    public String getMonth() {       return month;    }    public String getDay() {       return day;    }    public String...

  • solve it in c++ 10 note: please do not give me same answer like this 1....

    solve it in c++ 10 note: please do not give me same answer like this 1. Define a Pet class that stores the pet's name, age, and weight. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getLifespan that returns a string with the value "unknown lifespan." Next, define a Dog class that is derived from Pet. The Dog class should have a private member variable named breed that stores the breed of the dog. Add...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • 4. Create a Business class. This class should store an array of Employee objects. Add a...

    4. Create a Business class. This class should store an array of Employee objects. Add a method to add employees to the Business, similar to addFoodItem in the Meal class. Add two more methods for the Business class: getHighestPaid(), which returns the Employee who has been paid the most in total, and getHighestTaxed(), which returns the Employee who has been taxed the most in total. Note: you do not need to handle the case of ties. These are all the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT