Question

USING JAVA Write a program for calculating body fat and body fat percentage. The following simple...

USING JAVA

Write a program for calculating body fat and body fat percentage. The following simple formulas will be used for our calculations

Body fat formula for female:

A1 = (weight * .732) + 8.987

A2 = wrist measurement / 3.14

A3 = waist measurement * .157

A4 = hip measurement * .249

A5 = forearm measurement * .434

B = A1 + A2 - A3 – A4 + A5

Body fat = weight – B

Body fat percentage = Body fat * 100 / weight

Body fat formula for male:

A1 = (weight * 1.082) + 94.42

A2 = waist measurement * 4.15

B = A1 – A2

Body fat = weight – B

Body fat percentage = Body fat * 100 / weight

Your program should:

a. Ask for the gender and pertinent information for the given gender and calculate and display all the calculated values (A1, A2, etc.). For example, if the gender is Male, you don’t need the wrist measurement.

b. If a gender other than Male or Female is entered, issue an error message and do not calculate/display any data.

c. If the input weight is a negative number or is higher than 400, issue an error message and do not calculate/display any data.

d. Display the following information based on the calculated body fat percentage:

Less than 0 or higher than 400 = An error situation

0 or more, but less than 20   = OK

20 or more, but less than 50 = FINE

50 or more, but 400 or less = NOTHING we can do!

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


/*
* java program that prompts user to enter the male or female.
* Then weight, wrist, waise, hip and fore arm values from keybaord.
* Then display the results
* */
//BodyFat.java
import java.util.Scanner;
public class BodyFat
{
   public static void main(String[] args)
   {
       //create a Scanner class object
       Scanner console=new Scanner(System.in);
       String gender;
       double weight ;
       double wrist_measurement;
       double waist_measurement;
       double hip_measurement;
       double forearm_measurement;
       double B;
       double A1,A2,A3,A4,A5;
       double bodyfat;
       double fatpercent;

       System.out.printf("Enter male or female: ");
       gender=console.nextLine();
       //check if gender is not either male or female exit the program
       if(!gender.equals("male") && !gender.equals("female"))
       {
           System.out.println("Invalid");
           System.exit(0);
       }
       else
       {
           System.out.printf("Enter weight(kgs): ");
           weight=Double.parseDouble(console.nextLine());
          
           //exit the program if weight above 400
           if(weight<0 || weight>400)
           {
               System.out.println("Invalid");
               System.exit(0);
           }

           System.out.printf("Enter wrist_measurement: ");
           wrist_measurement=Double.parseDouble(console.nextLine());
           System.out.printf("Enter waist_measurement: ");
           waist_measurement=Double.parseDouble(console.nextLine());
           System.out.printf("Enter hip_measurement: ");
           hip_measurement=Double.parseDouble(console.nextLine());
           System.out.printf("Enter forearm_measurement: ");
           forearm_measurement=Double.parseDouble(console.nextLine());
           //check if gender is female
           if(gender.equals("female"))
           {
               A1=(weight*0.732)+8.987;
               A2 = wrist_measurement / 3.14;
               A3 = waist_measurement* .157;
               A4 = hip_measurement * .249;
               A5 =forearm_measurement * .434;
               B = A1 + A2 -A3-A4 + A5;
               bodyfat = weight-B;
               fatpercent = bodyfat * 100 / weight;
           }
           else//check if gender is male
           {
               A1 = (weight * 1.082) + 94.42;
               A2 = waist_measurement * 4.15;
               B = A1-A2;
               bodyfat= weight-B;
               fatpercent = bodyfat* 100.0/ weight;
           }
           //check if fatpercent
           if(fatpercent>400)
               System.out.println(" An error situation");
           else if(fatpercent>=0 && fatpercent<20)
               System.out.println("OK");
           else if(fatpercent>=20 && fatpercent<50)
               System.out.println("FINE");
           else if(fatpercent>=50 && fatpercent<400)
               System.out.println("NOTHING we can do!");
          
          
       }
   }
} //end of the class

Sample Output:

Add a comment
Know the answer?
Add Answer to:
USING JAVA Write a program for calculating body fat and body fat percentage. The following simple...
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
  • I'm having trouble rounding the numbers i'm getting in my output here's my code: #include<stdio.h> int...

    I'm having trouble rounding the numbers i'm getting in my output here's my code: #include<stdio.h> int main() { char gender; float a1, a2, a3, a4, a5; float waistmeasurement, wristmeasurement, hipmeasurement, forarmmeasurement; float B, bodyweight, Bodyfat, Bodyfatpercentage;    printf("This program determines the body fat of a person.Enter your gender (f|F|m|M): "); scanf("%c", &gender); printf("\n");    if(gender=='F' || gender=='f'){ printf("Enter body weight (in pounds): \n"); scanf("%f", &bodyweight); printf("Enter wrist measurement at fullest point (in inches): \n"); scanf("%f", &wristmeasurement); printf("Enter waist measurement at...

  • Write a Python program that asks the user to enter the number of calories and fat...

    Write a Python program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, therefore: Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as follows: Calories from fat / total calories If the calories from fat are less than 30 percent of the total...

  • 12 points) While obesity is measured based on body fat percentage (more than 35% body fat...

    12 points) While obesity is measured based on body fat percentage (more than 35% body fat for women and more than 25% for men), precisely measuring body fat percentage is difficult. Body mass index (BMI), calculated as the ratio weightheight2weightheight2 is often used as an alternative indicator for obesity. A common criticism of BMI is that it assumes the same relative body fat percentage regardless of age, sex, or ethnicity. In order to determine how useful BMI is for predicting...

  • 12 ponts while obesity s measured based on body fat percentage more than 35% body fat...

    12 ponts while obesity s measured based on body fat percentage more than 35% body fat for women and more than 25% or men precisely measuring body fat percentage 5 difficult Body mass ndex BMI calculated as the ratio as an alternative indicator for obesity. A common critcism of BMI is that it assumes the same relative body fat percentage regardless of age, sex, or ethnicity. In order to determine how useful BMI is for predicting body fat percentage across...

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

  • Write a Python program that does the following: Obtains the following input from a user: Mileage...

    Write a Python program that does the following: Obtains the following input from a user: Mileage at beginning of measurement period Mileage at end of measurement period Gallons of fuel consumed Calculates and displays: Miles driven Miles per gallon Kilometers driven Liters of fuel consumed Kilometers per liter Also incorporate some selection structure logic into it. If a vehicle gets less than 15 miles per gallon, display the message:       "Your vehicle has criminally low fuel efficiency." If it gets...

  • Using the data provided: Find the Mean and Standard deviation for: a. Popliteal height US Adult...

    Using the data provided: Find the Mean and Standard deviation for: a. Popliteal height US Adult Females, b. Sitting eye height US Adult Females, c. Forward reach of U.S. Adult Females. TT TT Paragraph Arial • 3(12pt) %DOQ SEET Os Mashups - 44 4 . E Words o Path:p Click Save and Submit to save and submit. Click Save All Answers to save all answers. Save All Answer 50-50 mixed male-female Table 4.2 Anthropometric data for the US adult population...

  • Question 1. Choose one of the three options described below. Analyze the data using what you hav...

    Question 1. Choose one of the three options described below. Analyze the data using what you have learned in class. Instructions: Your paper will include the following: A statement of the research question A description of the source of the data A description of the variables used in the analysis and an explanation of why you chose these variables Graphs (with clear labels) and numerical summaries to support your analysis Explanations that reflect the use of Unit 2 concepts An...

  • Write the following program in Java using Eclipse. A cash register is used in retail stores...

    Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

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