Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 2 Write the following programs: Print source code and output and turn in fo

ID: 3817440 • Letter: P

Question

Part 2 Write the following programs: Print source code and output and turn in for grading Write the following programs. Print source code and output and turn in for grading. 1) Use if lse if else type of constructs to write a program called "Height weight Ratio" The program assigns one double value height inches and one weight in pounds. Divide the weight by the height to find the ratio. Use the ratio to make a statement about their fitness if the ratio is less than 2.1 tell the user "his weight height ratio is normal" if the ratio is less than 2.3 tell the user they are slightly above average if the ratio is less than 2.5, tell the user they need to lose 5% percent of their weight"

Explanation / Answer


import java.util.*;
public class height_weight_ratio {
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       double ratios=0.0;
       System.out.println("Enter weight:");
       double weight=sc.nextInt();
       double pweight=2.2*weight;
       System.out.println("enter height:");
       double height=sc.nextInt();
       double pheight=height*0.3937;
       ratios=weight/height;
  
       String tosmall=String.valueOf(ratios);
       int index=0;
       for(int i=0;i<tosmall.length();i++){
           if(tosmall.charAt(i)=='.')
           index=i;
       }
  
       char arr[]=new char[index+2];
       System.out.println("ratio is:");
       for(int j=0;j<arr.length;j++){
           arr[j]=tosmall.charAt(j);
          
           System.out.print(arr[j]);
          
       }
       System.out.println();
       if(ratios<=2.1)
           System.out.println("weight height ratio is normal:");
       else if(ratios>2.1 && ratios<=2.3)
           System.out.println("you are slightly above the average:");
       else if(ratios>2.3 && ratios<2.5)
           System.out.println("you need to lose 5% of weight:");
       else if(ratios>=2.5)
           System.out.println("you need to lose more than 5% of weight:");
   }
}

output:

a)Enter weight:
145
enter height:
72
ratio is:
2.0
weight height ratio is normal:

output :
b)
Enter weight:
163
enter height:
72
ratio is:
2.2
you are slightly above the average:

output:
c)Enter weight:
165
enter height:
68
ratio is:
2.4
you need to lose 5% of weight:

output:
d)Enter weight:
185
enter height:
65
ratio is:
2.8
you need to lose more than 5% of weight: