Wednesday, June 20, 2012

Height Estimation Program, JAVA

/**
  * This program gives an estimate of a child's height using the formula:
* H(male) = (H(mother)*13/12 + H(father))/2
* H(female) = (H(father)*12/13 + H(mother))/2
* By allowing the user to input the height in feet and inches, conversions are possible.
*/

public class Username {

public static void main(String[] args) {
// Variable declarations

int mother_feet, mother_inches;
int father_feet, father_inches;
int child_total_inches;
Scanner scan = new Scanner(System.in);
String gender;
String male;
String female;
do{
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter the gender of the child. ");
gender = keyboard.nextLine();

System.out.println("Enter the height in feet then the height " +
"in inches of the mother.");
mother_feet = keyboard.nextInt();
mother_inches = keyboard.nextInt();

System.out.println("Enter the height in feet then the height " +
"in inches of the father.");
father_feet = keyboard.nextInt();
father_inches = keyboard.nextInt();

// Convert input to inches and estimate the adult height of the child
int mother_height = (mother_feet*12)+mother_inches;
int father_height = (father_feet*12)+father_inches;
if (gender.equals("male"))
{
// Male child formula
child_total_inches = ((mother_height * 13 / 12)
+ father_height)/2;
}
else
{
// Female child formula
child_total_inches = ((father_height * 12 / 13)
+ mother_height)/2;
}
// Output the estimated height
System.out.println("Your child is estimated to grow to " +
child_total_inches / 12 + " feet and " +
child_total_inches % 12 + " inches.");
System.out.println("Do you want to continue?");
String yes=keyboard.next("yes");
if (yes.equals(yes))
continue;
else
break;

}while(true);
}
} // Height

No comments:

Post a Comment