Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please l went do this program by use classes and do correct run CODE: import java.util.*; public class Main { //Function to read and return

please l went do this program by use classes and do correct run CODE: import java.util.*; public class Main { //Function to read and return the name of the customer public static String getName(){ Scanner scan = new Scanner(System.in); //creating scanner object System.out.println("Please enter your Name: "); String name = scan.nextLine(); //Reading the name of the customer return name; //return the customer name } //Function to read and return the gender of the customer public static int getGender(){ Scanner scan = new Scanner(System.in); //creating scanner object System.out.println("Please enter your Gender (1 for Male, 0 for Female): "); int gender = scan.nextInt(); //Reading the gender of the customer return gender; //return the customer gender } //Function to read and return the age of the customer public static int getAge(){ Scanner scan = new Scanner(System.in); //creating scanner object System.out.println("Please enter your Age: "); int age = scan.nextInt(); //Reading the age of the customer return age; //return the customer age } //Function to read and return the bmi of the customer public static double getBMI(){ Scanner scan = new Scanner(System.in); //creating scanner object System.out.println("Please enter your BMI: "); double bmi = scan.nextDouble(); //Reading the bmi of the customer return bmi; //return the customer bmi } public static double calculateBFP(int gender, int age, double bmi){ double bfp = 0; //calculate the child body fat percentage if(age <= 15){ bfp = (1.51 * bmi) - (0.70 * age) - (3.6 * gender) + 1.4; } //calculate the adult body fat percentage else if(age > 15){ bfp = (1.20 * bmi) + (0.23 * age) - (10.8 * gender) - 5.4; } return bfp; //return the customer bfp } public static double calculateAverage(double[] bfpArray){ double sum_bfp = 0; for(int i = 0; i< bfpArray.length; i++){ //loop through each bfp in bfpArray sum_bfp = sum_bfp + bfpArray[i]; //add the bfp value to sum_bfp } double avg_bfp = sum_bfp/bfpArray.length; //calculating the average bfp value return avg_bfp; //return the average bfp } public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Please enter the number of customers: "); int num_cust = scan.nextInt(); //Reading the number of customers double bfpArray[] = new double[num_cust]; //declare an array for bfp values String[] bfp_zone = {"Low Body Fat Risk", "Ultra Lean", "Lean", "Moderately Lean", "Excess fat", "High Body Fat Risk"}; double num_excess_fat = 0; for(int i=0; i 15) System.out.println("You are a Male adult"); } else if(gender == 0){ if(age <= 15) System.out.println("You are a Female child"); else if(age > 15) System.out.println("You are a Female adult"); } System.out.println("Your BMI is "+ String.format("%.2f", bmi)); //displaying then bmi System.out.println("Your BFP is "+ String.format("%.2f", bfp) +"% "); //displaying the bfp bfpArray[i] = bfp; //calculating number of persons in bfp zone - excess fat if(gender == 1){ if(bfp > 20 && bfp <= 30) num_excess_fat++; } else if(gender == 0){ if(bfp > 30 && bfp <= 40) num_excess_fat++; } } double avg_bfp = calculateAverage(bfpArray); //calling calculateAverage() double excess_fat_percent = (num_excess_fat/num_cust) * 100; //calculate the percentage of person that are in Excess fat System.out.println(" The average BFP of all "+ num_cust + " customers is " + String.format("%.2f", avg_bfp) +"%"); System.out.println("The percentage of person that are in BFP zone - Excess Fat is " + String.format("%.2f", excess_fat_percent) +"%"); } }

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

Students also viewed these Databases questions

Question

The company openly shares plans and information with employees.

Answered: 1 week ago