Question

In: Computer Science

Java Language Only Use Java FX In this project we will build a BMI calculator. BMI...

Java Language Only

Use Java FX

In this project we will build a BMI calculator. BMI is calculated using the following formulas:

Measurement Units Formula and Calculation
Kilograms and meters (or centimetres)

Formula: weight (kg) / [height (m)]2

The formula for BMI is weight in kilograms divided by height in meters squared. If height has been measured in centimetres, divide by 100 to convert this to meters.

Pounds and inches

Formula: 703 x weight (lbs) / [height (in)]2

When using English measurements, pounds should be divided by inches squared. This should then be multiplied by 703 to convert from lbs/inches2 to kg/m2.

Please update the BMIController.java file. Only modify the changeUnits and calculateResult methods.

BMI Controller code below:

package bmi;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

public class BMIController {
   @FXML
    private Button calculate;

    @FXML
    private Label heightLBL;
    @FXML
    private Label result;
    @FXML
    private Label weightLBL;

    @FXML
    private RadioButton us;
    @FXML
    private RadioButton metric;

    @FXML
    private TextField weightTF;
    @FXML
    private TextField heightTF;

    @FXML
    public void changeUnits(ActionEvent event) {
        //This method should update the labels to display correct unites
    }

    @FXML
    public void calculateResult(ActionEvent event) {
        // This method should calculate the BMI

    }
}

Solutions

Expert Solution

HI,

please find the code below.

@FXML
public void changeUnits(ActionEvent event)
{
//This method should update the labels to display correct unites
if(metric.isSelected())
{
weightLBL.setText(String.format("%.2f Metric System",w));
heightLBL.setText(String.format("%.2f Metric System",h));
}
else if(us.isSelected())
{
weightLBL.setText(String.format("%.2f US System",w));
heightLBL.setText(String.format("%.2f US System",h));
}
}

@FXML
public void calculateResult(ActionEvent event)
{
try
{
Double w = new Double(weight.getText());
Double h = new Double(height.getText());
//weight.setText(String.format("%.2f",w));
//height.setText(String.format("%.2f",h));
Double bmi;

if(metric.isSelected())
{
bmi = (w * 703.0)/(h*h);
result.setText(String.format("%.2f",bmi));
}
else if(us.isSelected())
{
bmi = w /(h*h);
result.setText(String.format("%.2f",bmi));
}
}catch(NumberFormatException nf)
{
weightTF.setText("Enter valid value");
weightTF.selectAll();
weightTF.requestFocus();
heightTF.setText("Enter valid value");
heightTF.selectAll();
}
}

thanks,

kindly upvote


Related Solutions

Java For this project, we want to build a calculator program that can perform simple calculations...
Java For this project, we want to build a calculator program that can perform simple calculations and provide an output. If it encounters any errors, it should print a helpful error message giving the nature of the error. You may use any combination of If-Then statements and Try-Catch statements to detect and handle errors. Program Specification Input Our program should accept input in one of two ways: If a command-line argument is provided, it should read input from the file...
create scientific calculator using java language with OOP rule and interfaces.
create scientific calculator using java language with OOP rule and interfaces.
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs in the data base are one-way. Question: Write a program that can answer if there is a path between any to vertices. For the vertex pairs use this as your input example: AL...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs are two-way. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of vertices traversed from X to Y if there is a path....
Be sure to use only C for the Programming Language in this problem. Before we start...
Be sure to use only C for the Programming Language in this problem. Before we start this, it is imperative that you understand the words “define”, “declare” and “initialize” in context of programming. It's going to help you a lot when following the guidelines below. Let's begin! Define two different structures at the top of your program. be sure to define each structure with exactly three members (each member has to be a different datatype). You may set them up...
Please Use C language to Make a calculator. Make sure calculator is able to take up...
Please Use C language to Make a calculator. Make sure calculator is able to take up to 5 values. Try to make calculator using simple coding As you can. Please create a simple calculator with only +, -,* and divide. It has to be able to enter any numbers (including decimals) and be able to do the following functions: +, -, divide and multiply. Please have the answers, always rounded to two decimal figures. The calculator will also have to...
In finance, we have to use financial calculator, how to use financial calculator, when we calculate the ordinary annuity and annuity due?
(1) In finance, we have to use financial calculator, how to use financial calculator, when we calculate the ordinary annuity and annuity due? could you give me some specific explanations?(2) When do we have to use annuity formula, FVA , PVA ? could you give me some explanations
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT