Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help please

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    5
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Help please

    I am trying to create a program that will estimate a child height based on the height of the parents.

    It should ask the user to enter a String representing the gender, so m or M for a male and f or F for a female. The program must handle both upper or lower case gender entries.
    I need it to ask the user for the height of both parents in two parts
    1. for Feet and store in an int variable.
    2. for inches and store and int variable.
    So for example if the father is 6' 2'', the user would enter 6 when asked for feet and 2 when asked for inches.
    Convert the height of the each parent to inches. hint 12" in one foot.
    Apply the following formulas based on gender (must use an if statement(s)):
    Hmale_child = ((Hmother * 13/12) + Hfather)/2
    Hfemale_child = ((Hfather * 13/12) + Hmother)/2

    I cannot figure out what is missing from my code

    <import java.util.Scanner;
     
    public class ChildHeight 
    { 
      public static void main(String[] args) 
     { 
       Scanner scannerObject = new Scanner(System.in); 
     
       String gender;
       String male;
       String female;
     
       int Hmother = 0, Hfather = 0; 
       int Hmale_child, Hfemale_child;
       int motherFeet, motherInches;
       int fatherFeet, fatherInches;
     
       System.out.println("Please enter the gender of the child, indicate M for male, F for female");
       gender = scannerObject.nextLine();
     
       System.out.println("Enter height of the mother in feet " + " height of the mother in inches");
       motherFeet = scannerObject.nextInt();
       motherInches = scannerObject.nextInt();
     
       System.out.println("Enter height of the father in feet " + " height of the father in inches");
       fatherFeet = scannerObject.nextInt();
       fatherInches = scannerObject.nextInt();
     
    // this is the formulas based on gender
      // Hmale_child = ((Hmother * 13/12) + Hfather)/2
      // Hfemale_child = ((Hfather * 13/12) + Hmother)/2   
     
       if (gender.equals("male"))
       { 
       System.out.println("Height of male child: " +((Hmother*(13/12)) + Hfather)/2);
     
       }
       else
       {
       System.out.println("Height of female child: " +((Hfather*(12/13)) + Hmother)/2);
       }
     
       System.out.println("The estimated height of the child is: ") ;
       }
     
     
    }>

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help please

    For one, comments are missing. Adding comments to your code that outline the assignment's requirements might also help you determine what else, if anything, is missing.

    If the user enters 'M' or 'm' for a male child, how will 'gender' be "male"?

    You've commented out important calculations. Without those, the answers will always be zero.

    This isn't magic, and it's a very simple code. Trace the logic, keep track of variable values in your head or on paper, and determine the outputs.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    Tripleg (June 21st, 2014)

  4. #3
    Member Abhilash's Avatar
    Join Date
    Jun 2014
    Location
    Kolkata, West Bengal, INDIA
    Posts
    108
    My Mood
    Busy
    Thanks
    5
    Thanked 10 Times in 10 Posts

    Default Re: Help please

    True. Considering you have asked for "M" or "F" and checking for "male" or "female". Just as GregBrannon said, this isn't magic. Maybe you took the question wrongly thinking M will yield male and F yields female. Moreover you have forgotten to calculate Hmother and Hfather from feet and inches.

  5. The Following User Says Thank You to Abhilash For This Useful Post:

    Tripleg (June 21st, 2014)