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

The Gray Method estimates the genetic potential a child has for reaching an adul

ID: 3904206 • Letter: T

Question

The Gray Method estimates the genetic potential a child has for reaching an adult height. If the child is a girl you multiple the father’s height by 12/13 and average the result with the mother’s height. The girl’s predicted height is the average minus 5 inches. If the child is a boy your multiple the mother’s height by 13/12 and average the result with the father’s height. The boy’s predicted height is the average plus 5 inches. The predicted height is reasonably accurate to plus or minus 5 inches.

Write a program asking:

·                      The father’s height

·                      The mother’s height

·                      The child’s gender

Calculate the potential height and print:

Explanation / Answer

PredictChildHeight.java

import java.util.Scanner;

public class PredictChildHeight {

public static void main(String[] args) {

  

//Declaring variables

double fHt,mHt,cHt;

char cGender;

  

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("Enter Father's Height (in Inches) :");

fHt=sc.nextDouble();

System.out.print("Enter Mother's Height (in Inches) :");

mHt=sc.nextDouble();

System.out.print("Enter Child's Gender :");

cGender=sc.next(".").charAt(0);

  

cHt=predictChildHt(fHt,mHt,cGender);

System.out.printf("The Predicted Child's Height : %.2f inches",cHt);

  

}

//This method will calculate the child's height

private static double predictChildHt(double fHt, double mHt, char cGender) {

double cHt = 0,res;

if(cGender=='m' || cGender=='M')

{

mHt=mHt*(13/12.0);

res=(fHt+mHt)/2;

cHt=res+5;

}

else if(cGender=='f' || cGender=='F')

{

fHt=fHt*(12/13.0);

res=(fHt+mHt)/2;

cHt=res-5;

}

return cHt;

}

}

_______________

Output:

Enter Father's Height (in Inches) :75
Enter Mother's Height (in Inches) :69
Enter Child's Gender :m
The Predicted Child's Height : 79.88

________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote