Question

(JAVA)Project 2: Predicting A Childs Height (10 pts). One way to estimate the adult height of a child is to use the following appr

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

/*
* Java program that prompts user to enter the feet and inches
* of father and mother of a child and then prompts for the
* gender m or f then find the height of the child in feet
* and inches
* */
import java.util.Scanner;
public class EstimatedHeight
{
   public static void main(String[] args)
   {      
       //declare varialbles
       int father_height;
       int mother_height;
       int child_height;
       int child_height_feet;
       int child_height_inches;

       String gender="";
       Scanner console=new Scanner(System.in);

       //read input data values from user
       System.out.printf("Enter height of father (in feet) : ");
       int father_height_feet = Integer.parseInt(console.nextLine());
       System.out.printf("Enter height of father (in inches) : ");
       int father_height_inches = Integer.parseInt(console.nextLine());

       System.out.printf("Enter height of mother (in feet) : ");
       int mother_height_feet = Integer.parseInt(console.nextLine());
       System.out.printf("Enter height of mother (in inches) : ");
       int mother_height_inches = Integer.parseInt(console.nextLine());
      
       System.out.printf("Enter Gender(m or f ):");
       gender=console.nextLine();

       //calculate the father height in inches
       father_height=12*father_height_feet+father_height_inches;
       //calculate the mother height in inches
       mother_height=12*mother_height_feet+mother_height_inches;

       //calculate the height of the child in inches
       if(gender.equalsIgnoreCase("m"))
           child_height=((mother_height*13/12)+father_height)/2;
       else
           child_height=((mother_height*12/13)+father_height)/2;

       //conver the child height in feet and inches
       child_height_feet=child_height/12;      
       child_height_inches=child_height%12;

       //print the child height in feet and inches
       System.out.printf("Height of child : %d\" %d\' \n",
               child_height_feet,child_height_inches);
   } //end of the method
}//end of the class

sample output:

Outputs of given sample values as test cases

Enter height of father in feet): 6 Enter height of father in inches): 3 Enter height of mother in feet): 5 Enter height of mo

Enter height of father in feet): 5 Enter height of father in inches) : 6 Enter height of mother (in feet): 5 Enter height of

Enter height of father in feet) : 5 Enter height of father in inches): 5 Enter height of mother in feet): 5 Enter height of m

Enter height of father in feet): 6 Enter height of father in inches): 0 Enter height of mother in feet): 5 Enter height of mo

Add a comment
Know the answer?
Add Answer to:
(JAVA) Project 2: Predicting A Child's Height (10 pts). One way to estimate the adult height...
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
  • JAVA Using the data provided in the attachment, create a program that will display a child's...

    JAVA Using the data provided in the attachment, create a program that will display a child's predicted adult height. This program will need to create an array of objects to search. This program needs to validate the input for valid range and input values. If invalid data is given, the program needs to indicate that data is invalid and suggest appropriate values/ranges. However, you do not need to validate alphabetic data given for numeric input. 1. The program will need...

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