Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please Use assignment # 2 (if you do not use the class you will get zero). Make the screen or GUI attached. They must apply

Please Use assignment # 2 (if you do not use the class you will get zero). Make the screen or GUI attached. They must apply Exception Handling.

Setters should not accept negative numbers.

the variables must be declared one per line.

That you see exactly everything like in the photo

image text in transcribed

assignment # 2: Please use this to do it (use the class).

package edu.pupr.BMI2;

import java.util.Scanner;

public class BMICalculation2 {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.print("How many pounds you weight? ");

double weight = in.nextDouble();

System.out.print("What is your height in inches? ");

double height = in.nextDouble();

try {

BMI2 bmi = new BMI2(weight, height);

bmi.printBMIResult();

} catch (Exception e) {

System.out.println("Error: " + e.getMessage());

}

}

}

public class BMI2

{

private double weight, height;

public BMI2(double weight, double height) { //Variables

this.weight = weight;

this.height = height;

}

public double getWeight() {

return weight;

}

public void setWeight(double weight) {

this.weight = weight;

}

public double getHeight() {

return height;

}

public void setHeight(double height) {

this.height = height;

}

public double calculateBMI() {

if(height == 0) throw new IllegalStateException("Height can not be zero.");

return (weight * 703) / (height * height);

}

public void printBMIResult() {

double bmi = calculateBMI();

String category;

if(bmi

category = "Underweight";

} else if(bmi

category = "Normal weight";

} else if(bmi

category = "Overweight";

} else {

category = "Obese";

}

System.out.printf("Your BMI is %.1f (%s) ", bmi, category);

}

}

BMI Calculator Height: 5ft 8 in. Weight: 200 Ibs Iculate Close 30.4 Obese

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

Explain walter's model of dividend policy.

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago