Search code examples
javaheight

Finding the height of a child based on the parents input


I've been trying to make a program in java to compute the height of a child based on the parents height in feet/inches, ans to estimate that answer based on the gender that the user input. I've been stumped on this for hours though. Seems like nothing I try is doing the right calculations.

Added a pic of how my program should look when it's done.

(( Example of how the output needs to look. ))

public static void main(String[] args) 
{
Scanner scan = new Scanner(System.in);
    
String userChoice;
int heightMom, heightDad, FemaleChildh, MaleChildh, genderChild;
    
System.out.println("Enter the gender of your future child. Use 1 for female, 
0 for male.");
genderChild = scan.nextInt();
    
System.out.println("Enter the height in feet, then the height in inches of 
the mom.");
heightMom = scan.nextInt();
    
System.out.println("Enter the height in feet, then the height in inches of 
the dad.");
heightDad = scan.nextInt();
    
MaleChildh = (heightMom*13/12 + heightDad)/2;
FemaleChildh = (heightDad+12/13 + heightMom)/2;
    
if (genderChild.equals(1))
System.out.println(("Your future child is estimated to grow 
to")+FemaleChildh);
   
if (genderChild.equals(0))
System.out.println(("Your future child is estimaed to grow to")+MaleChildh);
            
System.out.println("Enter 'Y' to run again, anything else to exit.");
userChoice = scan.next();
if (userChoice.equals("Y"))
System.out.println("Continuing...");
else if (userChoice.equals(""))
break;
}

Solution

  • Separate heightmom and heightdad into feet and inches. Use doubles to store your MaleChildh and FemaleChildh. Fix the typo with the word 'estimaed'.

    EDIT: See if you understand this code, then add the inch part to the child's height.

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
    
        String userChoice;
        int heightMomFt, heightMomIn, heightDadFt, heightDadIn, genderChild;
        double FemaleChildhFt, MaleChildhFt, FemaleChildhIn, MaleChildhIn;
        while (true) {
            System.out.println("Enter the gender of your future child. Use 1 for female, 0 for male.");
            genderChild = scan.nextInt();
    
            System.out.println("Enter the height in feet, then the height in inches of the mom.");
            heightMomFt = scan.nextInt();
            heightMomIn = scan.nextInt();
    
            System.out.println("Enter the height in feet, then the height in inches of the dad.");
            heightDadFt = scan.nextInt();
            heightDadIn = scan.nextInt();
    
            MaleChildhFt = (heightMomFt * 13 / 12 + heightDadFt) / 2;
            FemaleChildhFt = (heightDadFt + 12 / 13 + heightMomFt) / 2;
    
            if (genderChild == 1)
                System.out.println(("Your future child is estimated to grow to") + FemaleChildhFt);
    
            if (genderChild == 0)
                System.out.println(("Your future child is estimated to grow to") + MaleChildhFt);
    
            System.out.println("Enter 'Y' to run again, anything else to exit.");
            userChoice = scan.next();
            if (userChoice.equals("Y"))
                System.out.println("Continuing...");
            else
                break;
        }
    }