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...
Please code the following, using the language java! Build a simple calculator that ignores order of...
Please code the following, using the language java! Build a simple calculator that ignores order of operations. This “infix” calculator will read in a String from the user and calculate the results of that String from left to right. Consider the following left-to-right calculations: "4 + 4 / 2" "Answer is 4" //not 6, since the addition occurs first when reading from left to right “1 * -3 + 6 / 3” “Answer is 1” //and not -1Start by copying...
Language: Java(Netbeans) Implement a simple calculator.
Language: Java(Netbeans) Implement a simple calculator.
Please use Java language in an easy way with comments! Thanks! Create a calculator that uses...
Please use Java language in an easy way with comments! Thanks! Create a calculator that uses an array of buttons for numbers from 0-9, the . for decimals, and for operators +, -, * ,/ and = as well as a JTextfield that displays the current value or the result. Use ActionListeners and LayoutManagers appropriately. The example below shows how to determine which button has been clicked. ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand()); }...
JAVA PLEASE In this project, we are going to build a tiny database organized as a...
JAVA PLEASE In this project, we are going to build a tiny database organized as a singly linked list for storing and retrieving the information of a group of products on sale. The information of each product includes the following items: Product ID, Name, Seller, Quantity In Stock, Average Shipping Time, Original Price, Current Price. We assume that a node in the linked list should be defined by the following class. class Product {      long ID;      String name;...
Please use the Java Programming language. This is the introductory course, chapter two. Please only use...
Please use the Java Programming language. This is the introductory course, chapter two. Please only use if/else if, else and while loop. We have not touch base with do and while do(I don't know if while do exist in Java). Create an application that converts number grades to letter grades. Console Welcome to the Letter Grade Converter Enter numerical grade: 90 Letter grade: A Continue? (y/n): y Enter numerical grade: 88 Letter grade: A Continue? (y/n): y Enter numerical grade:...
create scientific calculator using java language with OOP rule and interfaces.
create scientific calculator using java language with OOP rule and interfaces.
create calculator standard using java language with OOP rule and interfaces.
create calculator standard using java language with OOP rule and interfaces.
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT