Answer to Question #253993 in Java | JSP | JSF for deee

Question #253993

Body Mass Index (BMI) is one of the criteria that is used to calculate whether one is fit or not basing on a person’s height (m) and weight (kg). The criterion is very simple; if one’s BMI is 25 or greater, it signifies overweight. A BMI less or equal to 18.5 indicates underweight. Lastly, a BMI greater than 30 shows obesity.

You have been requested to create a program that that helps the Namibian Defence Forces’ (NDF) Captain to calculates the BMI of a person (BMI = weight/height2) and also determine whether the person has also completed running 10 km in the required time. Men should complete 10km in less than 60 minutes for them to be accepted. Women should do that under 80 minutes. Both males and females are accepted if their BMI is less than 25 and greater than 18.5. For 2018 intake, there are already 6 males selected and 1 female. The values for gender, mass and weight are enter by user inputs


1
Expert's answer
2021-10-20T13:36:00-0400
import java.util.Scanner;

public class BodyMassIndex {

    float mass=0;
    float height=0;
    public static float distance=10;
    float time=0;
    float bmi;
    boolean gender;
    
    public BodyMassIndex(boolean gender,float m,float h,float t){
        this.mass=m;
        this.height=h;
        this.time=t;
        this.gender=gender;
        float bodyMassIndex=bmiCalculation(this.mass,this.height);
        BMI( bodyMassIndex,this.time,gender);
        
    }
    
            public float getMass() {
                return mass;
            }
        
            public void setMass(int mass) {
                this.mass = mass;
            }
        
            public float getHeight() {
                return height;
            }
        
            public void setHeight(int height) {
                this.height = height;
            }
        
                
            public float getTime() {
                return time;
            }
        
            public void setTime(float time) {
                this.time = time;
            }
            
            public void BMI(float bmi,float t,boolean gender){
                
                if(bmi<25 & bmi>18.5){
                    if(gender){
                        if(time<60){
                            
                            System.out.println("Candidate Accepted");
                            
                        }else{
                            
                            System.out.println("Candidate Rejected");
                            System.out.println("Disqualify in race");
                        }
                    
                    }else{
                        
                        if(time<80){
                            
                            System.out.println("Candidate Accepted");
                            
                            
                        }else{
                            
                            System.out.println("Candidate Rejected");
                            System.out.println("Disqualify in race");
                        
                        }
                    }
                }else{
                    
                    System.out.println("Candidate Rejected");
                    System.out.println("Disqualify in Body Mass Index");
                    
                }
            }
            public float bmiCalculation(float mass,float height){
                
                bmi=mass/(height*height);
                
                return bmi;
            }
            
            
            public static void main(String[] args) {
                // TODO Auto-generated method stub
                
                
                Scanner sc=new Scanner(System.in);
                
                System.out.println("If person is male: type - true");
                System.out.println("else type - false");
                boolean b=sc.nextBoolean();
                if(b){
                System.out.println("Candidate is Man");    
                }else{
                    System.out.println("Candidate is Woman");
                }
                
                System.out.println("Mass of the candidate:");
                float mass=sc.nextFloat();
                
                System.out.println("Height of the candidate:");
                float height=sc.nextFloat();
                
                System.out.println("Time taken by the candidate to complete the race:");
                float time=sc.nextFloat();

                BodyMassIndex bmi=new BodyMassIndex(b,mass,height,time);
               
               
            }
}

Output:

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS