Question

Please solve the following, please type out the code, and do not hand write because its hard to read. I would greatly appreciate it. (JAVA)

Problem 1 In a class called H1P1, write a method called bmiOne that takes as arguments a mass in kilograms (a double) and a h

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

// class definition

public class H1P1 {

//main function definition

public static void main(String[] args) {

//Create scanner object to take user input

Scanner sc = new Scanner(System.in);

//Prompt user to choose how they want to enter mass and height

System.out.println("Choose an option:");

System.out.println("1. Enter mass in kg and height in meters");

System.out.println("2. Enter mass in ponds and height in inches");

int option = sc.nextInt();

//Take user input for mass and height

System.out.println("Enter mass: ");

double mass = sc.nextDouble();

System.out.println("Enter height: ");

double height = sc.nextDouble();

//declare and initialize variable to store bmi

double bmi=0;

//call appropriate bmi function

if(option==1)

bmi=bmiOne(mass, height);

else if(option==2)

bmi=bmiTwo(mass, height);

//call function to print results

bmiPrinter(bmi);

}

//bmiOne function definition

public static double bmiOne(double mass, double height) {

//declare bmi variable nd initialize it to 0

double bmi=0;

//calculate bmi

bmi = mass / (height*height);

//return the bmi calculated

return bmi;

}

//bmiOne function definition

public static double bmiTwo(double weight, double height) {

//declare bmi variable nd initialize it to 0

double bmi=0;

//calculate bmi

bmi = (weight / (height*height))*703;

//return the bmi calculated

return bmi;

}

//function definition to print result

public static void bmiPrinter(double bmi) {

System.out.println("Your BMI value is : " + bmi + ".\nPlease refer to the table below to check the category for this value:");

System.out.println("\n--------------------------------------------");

System.out.println("| BMI | Category |");

System.out.println("--------------------------------------------");

System.out.println("| From 16.0 to 18.5 | Underweigth |");

System.out.println("--------------------------------------------");

System.out.println("| From 18.5 to 25 | Normal |");

System.out.println("--------------------------------------------");

System.out.println("| From 25 to 30 | Overweight |");

System.out.println("--------------------------------------------");

System.out.println("| From 30 to 35 | Moderately Obese |");

System.out.println("--------------------------------------------");

System.out.println("| From 35 to 40 | Severly Obese |");

System.out.println("--------------------------------------------");

}

}

I I l I Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches Enter mass: 50

I I Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches 2 Enter mass: 80 E

I l I Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches Enter mass: 100

I Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches Enter mass: 45 Enter

I I | Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches Enter mass: 75 E

I I l l Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches Enter mass: 13

I I Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches 2 Enter mass: 100

I | Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches Enter mass: 150 En

I I I | Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches Enter mass: 12

Choose an option: 1. Enter mass in kg and height in meters 2. Enter mass in ponds and height in inches 2 Enter mass: 80 Enter

Add a comment
Know the answer?
Add Answer to:
Please solve the following, please type out the code, and do not hand write because its...
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
  • 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...

  • + Run C Code IMPORTANT: • Run the following code cell to create the input file,...

    + Run C Code IMPORTANT: • Run the following code cell to create the input file, biostats.csv, which you will be using later. 74, In [ ]: N %%file biostats.csv Name, Sex, Age, Alex, M, 41, Bert, M, 42, Dave, M, 39, Elly, F, 30, Fran, F, 33, Jake, M, F, Luke, M, 34, F Myra, M, M, 38, Ruth, F, 28, 22 22 323 47 47, Height, Weight 170 200 167 70 115 143 139 280 98 75, 350...

  • python2.7 25 Points. Create a class named BMIGUI with the following behavior. A template has been...

    python2.7 25 Points. Create a class named BMIGUI with the following behavior. A template has been provided for you and you cannot modify the template. You must use grid) to format the interface and you must get as close as possible the layout shown below. The entry box has a width parameter in its constructor you can use to make the box smaller 3. The BMI categories are as follows: Underweight= <18.5 Normal weight18.5-24.9 . Overweight 25-29.9 Obese BMI of...

  • BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that...

    BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that takes users' input (weight and Height) and calculates the BMI. If the result is less than 18.5 display "you are underweight", if the result is greater than 18.5 display "you have a normal weight", if the result is greater than 24.9 display "your weight is considered overweight", and the result is greater than 30 display "your weight is considered as obese" (BMI = 703...

  • Weight: 131 lbs Female Height: 5 ft 2 inches Calculate, showing the math, your Body Mass...

    Weight: 131 lbs Female Height: 5 ft 2 inches Calculate, showing the math, your Body Mass Index (BMI) using the formula 'weight in kilograms divided by height in meters squared' (kg/m^2). Note: Weight in pounds divided by 2.2 = weight in kg and height in inches times .0254 = height in meters. The number is absolute and not a percentage. Based on your BMI, are you underweight, healthy weight, overweight, or obese?

  • 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.

  • The body mass index (BMI estimates the amount of fat in a person's body. It is defined as the person's mass m in kilograms divided by the square of the person's height h in meters. Write...

    The body mass index (BMI estimates the amount of fat in a person's body. It is defined as the person's mass m in kilograms divided by the square of the person's height h in meters. Write the formula for BMI in terms of m and h. 0 BMI In the United States, most people measure weight in pounds and height in feet and inches. When weight W is measured in pounds and height h is measured in inches, the BMI...

  • Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and...

    Please write this code in C++ Object-Oriented Programming, specify which files are .h, and .cpp, and please add comments for the whole code. Include a class diagrams, and explain the approach you used for the project and how you implemented that, briefly in a few sentences. Please note the following: -Names chosen for classes, functions, and variables should effectively convey the purpose and meaning of the named entity. - Code duplication should be avoided by factoring out common code into...

  • - A pseudo code that prompts the user for the grades of four exams and prints...

    - A pseudo code that prompts the user for the grades of four exams and prints its average and then code in JAVA - A pseudo code that prompts the user for value in meters and converts it to feet and inches. Print both results.  and then code in JAVA -A pseudo code that will calculate the users Body Mass Index (BMI) and then display it for the user to see. Prompt the user to input their weight (in pounds) and...

  • OGICAL 28. Body mass index (BMI) is a measure of obesity. In standard units, it is...

    OGICAL 28. Body mass index (BMI) is a measure of obesity. In standard units, it is calculated by the formula EMENTS BMI = 7032 ATEMENT NESTED INTS where Wis weight in pounds, and His height in inches. The obesity classification is BMI Classification Below 18.5 Underweight 18.5 to 24.9 Normal 25 to 29.9 Overweight 30 and above Obese Tue Write a program in a script file that calculates the BMI of a person. The program asks the person to enter...

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
ADVERTISEMENT